Add data-provider
[ccsdk/features.git] / sdnr / wt / odlux / apps / helpApp / webpack.config.js
1 /**
2  * Webpack 4 configuration file
3  * see https://webpack.js.org/configuration/
4  * see https://webpack.js.org/configuration/dev-server/
5  */
6
7 "use strict";
8
9 const path = require("path");
10 const webpack = require("webpack");
11 const autoprefixer = require('autoprefixer');
12 const CopyWebpackPlugin = require("copy-webpack-plugin");
13 const TerserPlugin = require('terser-webpack-plugin');
14
15 // const __dirname = (path => path.replace(/^([a-z]\:)/, c => c.toUpperCase()))(process.__dirname());
16
17 module.exports = (env) => {
18   const distPath = path.resolve(__dirname, env === "release" ? "." : "../..", "dist");
19   const frameworkPath = path.resolve(__dirname, env === "release" ? "../../framework" : "../..", "dist");
20   return [{
21     name: "App",
22
23     mode: "none", //disable default behavior
24
25     target: "web",
26
27     context: path.resolve(__dirname, "src"),
28
29     entry: {
30       helpApp: ["./plugin.tsx"]
31     },
32
33     devtool: env === "release" ? false : "source-map",
34
35     resolve: {
36       extensions: [".ts", ".tsx", ".js", ".jsx"]
37     },
38
39     output: {
40       path: distPath,
41       filename: "[name].js",
42       library: "[name]",
43       libraryTarget: "umd2",
44       chunkFilename: "[name].js"
45     },
46     module: {
47       rules: [{
48         test: /\.tsx?$/,
49         exclude: /node_modules/,
50         use: [{
51           loader: "babel-loader"
52         }, {
53           loader: "ts-loader"
54         }]
55       }, {
56         test: /\.jsx?$/,
57         exclude: /node_modules/,
58         use: [{
59           loader: "babel-loader"
60         }]
61       }, {
62         test: /\.css$/,
63         use: [{
64           loader: 'style-loader'
65         }, {
66           loader: 'css-loader',
67           options: {
68             modules: true,
69             localIdentName: env !== "release" ? '[name]_[local]_[hash:base64:5]' : '[hash]'
70           }
71         }, {
72           loader: 'postcss-loader',
73           options: {
74             plugins: () => [autoprefixer]
75           }
76         }]
77       }]
78     },
79
80     optimization: {
81       noEmitOnErrors: true,
82       namedModules: env !== "release",
83       minimize: env === "release",
84       minimizer: env !== "release" ? [] : [new TerserPlugin({
85         terserOptions: {
86           warnings: false, // false, true, "verbose"
87           compress: {
88             drop_console: true,
89             drop_debugger: true,
90           }
91         }
92       })],
93     },
94
95     plugins: [
96       new webpack.DllReferencePlugin({
97         context: path.resolve(__dirname, "../../framework/src"),
98         manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")),
99         sourceType: "umd2"
100       }),
101       new webpack.DllReferencePlugin({
102         context: path.resolve(__dirname, "../../framework/src"),
103         manifest: require(path.resolve(frameworkPath, "app-manifest.json")),
104         sourceType: "umd2"
105       }),
106       ...(env === "release") ? [
107         new webpack.DefinePlugin({
108           "process.env": {
109             NODE_ENV: "'production'",
110             VERSION: JSON.stringify(require("./package.json").version)
111           }
112         }),
113       ] : [
114           new webpack.DefinePlugin({
115             "process.env": {
116               NODE_ENV: "'development'",
117               VERSION: JSON.stringify(require("./package.json").version)
118             }
119           }),
120           new CopyWebpackPlugin([{
121             from: 'index.html',
122             to: distPath
123           }]),
124         ]
125     ],
126     devServer: {
127       public: "http://localhost:3100",
128       contentBase: frameworkPath,
129
130       compress: true,
131       headers: {
132         "Access-Control-Allow-Origin": "*"
133       },
134       host: "0.0.0.0",
135       port: 3100,
136       disableHostCheck: true,
137       historyApiFallback: true,
138       inline: true,
139       hot: false,
140       quiet: false,
141       stats: {
142         colors: true
143       },
144       proxy: {
145         "/oauth2/": {
146           target: "http://localhost:3000",
147           secure: false
148         },
149         "/database/": {
150           target: "http://localhost:3000",
151           secure: false
152         },
153         "/restconf/": {
154           target: "http://localhost:3000",
155           secure: false
156         },
157         "/help/": {
158           target: "http://localhost:3000",
159           secure: false
160         },
161         "/websocket/": {
162           target: "http://localhost:3000",
163           ws: true,
164           changeOrigin: true,
165           secure: false
166         }
167       }
168     }
169   }];
170 }