e3f3b6f19458b3d1e108a9e497cc3a67569b8fc1
[ccsdk/features.git] / sdnr / wt / odlux / apps / configurationApp / 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 policies = require('./policies.json');
15
16 // const __dirname = (path => path.replace(/^([a-z]\:)/, c => c.toUpperCase()))(process.__dirname());
17
18 module.exports = (env) => {
19   const distPath = path.resolve(__dirname, env === "release" ? "." : "../..", "dist");
20   const frameworkPath = path.resolve(__dirname, env === "release" ? "../../framework" : "../..", "dist");
21   return [{
22     name: "App",
23
24     mode: "none", //disable default behavior
25
26     target: "web",
27
28     context: path.resolve(__dirname, "src"),
29
30     entry: {
31       configurationApp: ["./pluginConfiguration.tsx"]
32     },
33
34     devtool: env === "release" ? false : "source-map",
35
36     resolve: {
37       extensions: [".ts", ".tsx", ".js", ".jsx"]
38     },
39
40     output: {
41       path: distPath,
42       filename: "[name].js",
43       library: "[name]",
44       libraryTarget: "umd2",
45       chunkFilename: "[name].js"
46     },
47     module: {
48       rules: [{
49         test: /\.tsx?$/,
50         exclude: /node_modules/,
51         use: [{
52           loader: "babel-loader"
53         }, {
54           loader: "ts-loader"
55         }]
56       }, {
57         test: /\.jsx?$/,
58         exclude: /node_modules/,
59         use: [{
60           loader: "babel-loader"
61         }]
62       }]
63     },
64
65     optimization: {
66       noEmitOnErrors: true,
67       namedModules: env !== "release",
68       minimize: env === "release",
69       minimizer: env !== "release" ? [] : [new TerserPlugin({
70         terserOptions: {
71           warnings: false, // false, true, "verbose"
72           compress: {
73             drop_console: true,
74             drop_debugger: true,
75           }
76         }
77       })],
78     },
79
80     plugins: [
81       new webpack.DllReferencePlugin({
82         context: path.resolve(__dirname, "../../framework/src"),
83         manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")),
84         sourceType: "umd2"
85       }),
86       new webpack.DllReferencePlugin({
87         context: path.resolve(__dirname, "../../framework/src"),
88         manifest: require(path.resolve(frameworkPath, "app-manifest.json")),
89         sourceType: "umd2"
90       }),
91       ...(env === "release") ? [
92         new webpack.DefinePlugin({
93           "process.env": {
94             NODE_ENV: "'production'",
95             VERSION: JSON.stringify(require("./package.json").version)
96           }
97         }),
98       ] : [
99           new webpack.DefinePlugin({
100             "process.env": {
101               NODE_ENV: "'development'",
102               VERSION: JSON.stringify(require("./package.json").version)
103             }
104           }),
105           new CopyWebpackPlugin([{
106             from: 'index.html',
107             to: distPath
108           }]),
109         ]
110     ],
111
112      watchOptions: {
113        ignored: /node_modules/
114      },
115
116     devServer: {
117       contentBase: frameworkPath,
118
119       compress: true,
120       headers: {
121         "Access-Control-Allow-Origin": "*"
122       },
123       host: "0.0.0.0",
124       port: 3100,
125       disableHostCheck: true,
126       historyApiFallback: true,
127       inline: true,
128       hot: false,
129       quiet: false,
130       stats: {
131         colors: true
132       },
133       before: function(app, server, compiler) {
134         app.get('/oauth/policies',(_, res) => res.json(policies));
135       },
136        proxy: {
137         "/about": {
138           target: "http://localhost:18181",
139           secure: false
140         }, 
141         "/yang-schema/": {
142           target: "http://localhost:18181",
143           secure: false
144         },   
145         "/oauth/": {
146           target: "http://localhost:18181",
147           secure: false
148         },
149         "/database/": {
150           target: "http://localhost:18181",
151           secure: false
152         },
153         "/restconf/": {
154           target: "http://localhost:18181",
155           secure: false
156         },
157         "/rests/": {
158           target: "http://localhost:18181",
159           secure: false
160         },
161         "/help/": {
162           target: "http://localhost:18181",
163           secure: false
164         },
165          "/about/": {
166           target: "http://localhost:18181",
167           secure: false
168         },
169         "/tree/": {
170           target: "http://localhost:18181",
171           secure: false
172         },
173         "/websocket": {
174           target: "http://localhost:18181",
175           ws: true,
176           changeOrigin: true,
177           secure: false
178         },
179         "/apidoc": {
180           target: "http://localhost:18181",
181           ws: true,
182           changeOrigin: true,
183           secure: false
184         }
185       }
186     }
187   }];
188 }