61dd8f6f6deadd02b24a6ffcece4ba0644a4b630
[ccsdk/features.git] / sdnr / wt / odlux / apps / demoApp / 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       demoApp: ["./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     },
62     optimization: {
63       noEmitOnErrors: true,
64       namedModules: env !== "release",
65       minimize: env === "release",
66       minimizer: env !== "release" ? [] : [new TerserPlugin({
67         terserOptions: {
68           warnings: false, // false, true, "verbose"
69           compress: {
70             drop_console: true,
71             drop_debugger: true,
72           }
73         }
74       })],
75     },
76     plugins: [
77       new webpack.DllReferencePlugin({
78         context: path.resolve(__dirname, "../../framework/src"),
79         manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")),
80         sourceType: "umd2"
81       }),
82       new webpack.DllReferencePlugin({
83         context: path.resolve(__dirname, "../../framework/src"),
84         manifest: require(path.resolve(frameworkPath, "app-manifest.json")),
85         sourceType: "umd2"
86       }),
87       ...(env === "release") ? [
88         new webpack.DefinePlugin({
89           "process.env": {
90             NODE_ENV: "'production'",
91             VERSION: JSON.stringify(require("./package.json").version)
92           }
93         }),
94       ] : [
95           new webpack.DefinePlugin({
96             "process.env": {
97               NODE_ENV: "'development'",
98               VERSION: JSON.stringify(require("./package.json").version)
99             }
100           }),
101           new CopyWebpackPlugin([{
102             from: 'index.html',
103             to: distPath
104           }]),
105         ]
106     ],
107
108     devServer: {
109       public: "http://localhost:3100",
110       contentBase: frameworkPath,
111
112       compress: true,
113       headers: {
114         "Access-Control-Allow-Origin": "*"
115       },
116       host: "0.0.0.0",
117       port: 3100,
118       disableHostCheck: true,
119       historyApiFallback: true,
120       inline: true,
121       hot: false,
122       quiet: false,
123       stats: {
124         colors: true
125       },
126       proxy: {
127         "/api": {
128           target: "http://localhost:3001",
129           secure: false
130         }
131       }
132     }
133   }];
134 }