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