Create wt-odlux directory
[ccsdk/features.git] / sdnr / wt-odlux / odlux / apps / configurationApp / 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 CopyWebpackPlugin = require("copy-webpack-plugin");
12 const TerserPlugin = require('terser-webpack-plugin');
13 const proxyConf = require('../../proxy.conf');
14
15 const policies = require('./policies.json');
16
17 // const __dirname = (path => path.replace(/^([a-z]\:)/, c => c.toUpperCase()))(process.__dirname());
18
19 module.exports = (env) => {
20   const distPath = path.resolve(__dirname, env === "release" ? "." : "../..", "dist");
21   const frameworkPath = path.resolve(__dirname, env === "release" ? "../../framework" : "../..", "dist");
22   return [{
23     name: "App",
24
25     mode: "none", //disable default behavior
26
27     target: "web",
28
29     context: path.resolve(__dirname, "src"),
30
31     entry: {
32       configurationApp: ["./pluginConfiguration.tsx"]
33     },
34
35     devtool: env === "release" ? false : "source-map",
36
37     resolve: {
38       extensions: [".ts", ".tsx", ".js", ".jsx"]
39     },
40
41     output: {
42       path: distPath,
43       filename: "[name].js",
44       library: "configurationApp",
45       libraryTarget: "umd2",
46       chunkFilename: "[name].js"
47     },
48     module: {
49       rules: [{
50         test: /\.tsx?$/,
51         exclude: /node_modules/,
52         use: [{
53           loader: "babel-loader"
54         }, {
55           loader: "ts-loader"
56         }]
57       }, {
58         test: /\.jsx?$/,
59         exclude: /node_modules/,
60         use: [{
61           loader: "babel-loader"
62         }]
63       },{
64         //don't minify images
65         test: /\.(png|gif|jpg|svg)$/,
66         use: [{
67           loader: 'url-loader',
68           options: {
69             limit: 10,
70             name: './images/[name].[ext]'
71           }
72         }]
73       }]
74     },
75
76     optimization: {
77       noEmitOnErrors: true,
78       namedModules: env !== "release",
79       minimize: env === "release",
80       minimizer: env !== "release" ? [] : [new TerserPlugin({
81         terserOptions: {
82           warnings: false, // false, true, "verbose"
83           compress: {
84             drop_console: true,
85             drop_debugger: true,
86           }
87         }
88       })],
89     },
90
91     plugins: [
92       new webpack.DllReferencePlugin({
93         context: path.resolve(__dirname, "../../framework/src"),
94         manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")),
95         sourceType: "umd2"
96       }),
97       new webpack.DllReferencePlugin({
98         context: path.resolve(__dirname, "../../framework/src"),
99         manifest: require(path.resolve(frameworkPath, "app-manifest.json")),
100         sourceType: "umd2"
101       }),
102       ...(env === "release" ? [
103         new webpack.DefinePlugin({
104           "process.env": {
105             NODE_ENV: "'production'",
106             VERSION: JSON.stringify(require("./package.json").version)
107           }
108         }),
109       ] : [
110           new webpack.DefinePlugin({
111             "process.env": {
112               NODE_ENV: "'development'",
113               VERSION: JSON.stringify(require("./package.json").version)
114             }
115           }),
116           new CopyWebpackPlugin([{
117             from: 'index.html',
118             to: distPath
119           }]),
120         ])
121     ],
122
123      watchOptions: {
124        ignored: /node_modules/
125      },
126
127     devServer: {
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       before: function(app, server, compiler) {
145         app.get('/oauth/policies',(_, res) => res.json(policies));
146       },
147       proxy: proxyConf,
148     }
149   }];
150 }