Merge "refactor devicemanager-core"
[ccsdk/features.git] / sdnr / wt / odlux / apps / networkMapApp / 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       networkMapApp: ["./pluginTransport.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         test: /\.(png|gif|jpg|svg)$/,
63         use: [{
64           loader: 'url-loader',
65           options: {
66             limit: 10000,
67             name: './icons/[hash].[ext]'
68           }
69         }]
70       },
71       {
72         test: /\.css$/i,
73         use: ["style-loader", "css-loader"],
74       }]
75     },
76
77     optimization: {
78       noEmitOnErrors: true,
79       namedModules: env !== "release",
80       minimize: env === "release",
81       minimizer: env !== "release" ? [] : [new TerserPlugin({
82         terserOptions: {
83           warnings: false, // false, true, "verbose"
84           compress: {
85             drop_console: true,
86             drop_debugger: true,
87           }
88         }
89       })],
90     },
91
92     plugins: [
93       new webpack.DllReferencePlugin({
94         context: path.resolve(__dirname, "../../framework/src"),
95         manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")),
96         sourceType: "umd2"
97       }),
98       new webpack.DllReferencePlugin({
99         context: path.resolve(__dirname, "../../framework/src"),
100         manifest: require(path.resolve(frameworkPath, "app-manifest.json")),
101         sourceType: "umd2"
102       }),
103       ...(env === "release") ? [
104         new webpack.DefinePlugin({
105           "process.env": {
106             NODE_ENV: "'production'",
107             VERSION: JSON.stringify(require("./package.json").version)
108           }
109         }),
110       ] : [
111           new webpack.DefinePlugin({
112             "process.env": {
113               NODE_ENV: "'development'",
114               VERSION: JSON.stringify(require("./package.json").version)
115             }
116           }),
117           new CopyWebpackPlugin([{
118             from: 'index.html',
119             to: distPath
120           }]),
121         ]
122     ],
123
124     devServer: {
125       public: "http://localhost:3100",
126       contentBase: frameworkPath,
127
128       compress: true,
129       headers: {
130         "Access-Control-Allow-Origin": "*"
131       },
132       host: "0.0.0.0",
133       port: 3100,
134       disableHostCheck: true,
135       historyApiFallback: true,
136       inline: true,
137       hot: false,
138       quiet: false,
139       stats: {
140         colors: true
141       },
142       proxy: {
143         "/yang-schema/": {
144           target: "http://sdnr:8181",
145           secure: false
146         },  
147         "/userdata": {
148           target: "http://sdnr:8181",
149           secure: false
150         },  
151         "/userdata/": {
152           target: "http://sdnr:8181",
153           secure: false
154         }, 
155         "/oauth2/": {
156           target: "http://sdnr:8181",
157           secure: false
158         },
159         "/database/": {
160           target: "http://sdnr:8181",
161           secure: false
162         },
163         "/restconf/": {
164           target: "http://sdnr:8181",
165           secure: false
166         },
167         "/rests/": {
168           target: "http://sdnr:8181",
169           secure: false
170         },
171         "/topology/": {
172           target: "http://localhost:3002",
173           secure: false
174         },
175         "/sitedoc/": {
176           target: "http://localhost:3002",
177           secure: false,
178           pathRewrite(pathname) {
179             return pathname.replace(/^\/sitedoc/, '/topology/stadok')
180           }
181         },
182         "/tiles/": {
183           target: "http://tile.openstreetmap.org",
184           secure: false
185         },
186         "/help/": {
187           target: "http://sdnr:8181",
188           secure: false
189         },
190         "/websocket": {
191           target: "http://sdnr:8181",
192           ws: true,
193           changeOrigin: true,
194           secure: false
195         }
196       }
197
198     }
199   }];
200 }