Create wt-odlux directory
[ccsdk/features.git] / sdnr / wt-odlux / odlux / apps / performanceHistoryApp / 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       performanceHistoryApp: ["./pluginPerformance.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     plugins: [
88       new webpack.DllReferencePlugin({
89         context: path.resolve(__dirname, "../../framework/src"),
90         manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")),
91         sourceType: "umd2"
92       }),
93       new webpack.DllReferencePlugin({
94         context: path.resolve(__dirname, "../../framework/src"),
95         manifest: require(path.resolve(frameworkPath, "app-manifest.json")),
96         sourceType: "umd2"
97       }),
98       ...(env === "release" ? [
99         new webpack.DefinePlugin({
100           "process.env": {
101             NODE_ENV: "'production'",
102             VERSION: JSON.stringify(require("./package.json").version)
103           }
104         }),
105       ] : [
106           new webpack.DefinePlugin({
107             "process.env": {
108               NODE_ENV: "'development'",
109               VERSION: JSON.stringify(require("./package.json").version)
110             }
111           }),
112           new CopyWebpackPlugin([{
113             from: 'index.html',
114             to: distPath
115           }]),
116         ])
117     ],
118
119     devServer: {
120       public: "http://localhost:3100",
121       contentBase: frameworkPath,
122
123       compress: true,
124       headers: {
125         "Access-Control-Allow-Origin": "*"
126       },
127       host: "0.0.0.0",
128       port: 3100,
129       disableHostCheck: true,
130       historyApiFallback: true,
131       inline: true,
132       hot: false,
133       quiet: false,
134       stats: {
135         colors: true
136       },
137       proxy: {
138         "/oauth2/": {
139           target: "http://10.20.6.29:48181",
140           secure: false
141         },
142         "/database/": {
143           target: "http://10.20.6.29:48181",
144           secure: false
145         },
146         "/restconf/": {
147           target: "http://10.20.6.29:48181",
148           secure: false
149         },
150         "/rests/": {
151           target: "http://10.20.6.29:48181",
152           secure: false
153         },
154         "/help/": {
155           target: "http://10.20.6.29:48181",
156           secure: false
157         },
158         "/websocket": {
159           target: "http://10.20.6.29:48181",
160           ws: true,
161           changeOrigin: true,
162           secure: false
163         }
164       }
165     }
166   }];
167 }