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