Create wt-odlux directory
[ccsdk/features.git] / sdnr / wt-odlux / 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         //don't minify images
79         test: /\.(png|gif|jpg|svg)$/,
80         use: [{
81           loader: 'url-loader',
82           options: {
83             limit: 10,
84             name: './images/[name].[ext]'
85           }
86         }]
87       }]
88     },
89
90     optimization: {
91       noEmitOnErrors: true,
92       namedModules: env !== "release",
93       minimize: env === "release",
94       minimizer: env !== "release" ? [] : [new TerserPlugin({
95         terserOptions: {
96           warnings: false, // false, true, "verbose"
97           compress: {
98             drop_console: true,
99             drop_debugger: true,
100           }
101         }
102       })],
103     },
104
105     plugins: [
106       new webpack.DllReferencePlugin({
107         context: path.resolve(__dirname, "../../framework/src"),
108         manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")),
109         sourceType: "umd2"
110       }),
111       new webpack.DllReferencePlugin({
112         context: path.resolve(__dirname, "../../framework/src"),
113         manifest: require(path.resolve(frameworkPath, "app-manifest.json")),
114         sourceType: "umd2"
115       }),
116       ...(env === "release" ? [
117         new webpack.DefinePlugin({
118           "process.env": {
119             NODE_ENV: "'production'",
120             VERSION: JSON.stringify(require("./package.json").version)
121           }
122         }),
123       ] : [
124           new webpack.DefinePlugin({
125             "process.env": {
126               NODE_ENV: "'development'",
127               VERSION: JSON.stringify(require("./package.json").version)
128             }
129           }),
130           new CopyWebpackPlugin([{
131             from: 'index.html',
132             to: distPath
133           }]),
134         ])
135     ],
136     devServer: {
137       public: "http://localhost:3100",
138       contentBase: frameworkPath,
139
140       compress: true,
141       headers: {
142         "Access-Control-Allow-Origin": "*"
143       },
144       host: "0.0.0.0",
145       port: 3100,
146       disableHostCheck: true,
147       historyApiFallback: true,
148       inline: true,
149       hot: false,
150       quiet: false,
151       stats: {
152         colors: true
153       },
154       proxy: {
155         "/oauth2/": {
156           //target: "http://10.20.6.29:48181",
157           target: "http://sdnr:8181",
158           secure: false
159         },
160         "/database/": {
161           //target: "http://10.20.6.29:48181",
162           target: "http://sdnr:8181",
163           secure: false
164         },
165         "/restconf/": {
166           //target: "http://10.20.6.29:48181",
167           target: "http://sdnr:8181",
168           secure: false
169         },
170         "/rests/": {
171           target: "http://sdnr:8181",
172           secure: false
173         },
174         "/help/": {
175           //target: "http://10.20.6.29:48181",
176           target: "http://sdnr:8181",
177           secure: false
178         },
179         "/websocket/": {
180           //target: "http://10.20.6.29:48181",
181           target: "http://sdnr:8181",
182           ws: true,
183           changeOrigin: true,
184           secure: false
185         }
186       }
187     }
188   }];
189 }