blob: 3c9093c4b5203e13e1474ab3b59ce5e2810b3feb [file] [log] [blame]
Aijana Schumann4bd84be2020-08-27 09:01:53 +02001/**
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
9const path = require("path");
10const webpack = require("webpack");
11const CopyWebpackPlugin = require("copy-webpack-plugin");
12const TerserPlugin = require('terser-webpack-plugin');
13
14// const __dirname = (path => path.replace(/^([a-z]\:)/, c => c.toUpperCase()))(process.__dirname());
15
16module.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 linkCalculationApp: ["./pluginLinkCalculation.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 }, {
Mohammadda4768f2020-11-09 15:59:34 +010052 loader: "ts-loader"
Aijana Schumann4bd84be2020-08-27 09:01:53 +020053 }]
54 }, {
55 test: /\.jsx?$/,
56 exclude: /node_modules/,
57 use: [{
58 loader: "babel-loader"
59 }]
Mohammadda4768f2020-11-09 15:59:34 +010060 },{
61 test: /\.scss$/,
62 include: /node_modules/,
63 use: ['style-loader', 'css-loader', 'sass-loader'],
64 },{
65 test: /\.s[ac]ss$/i,
66 use: [
67 // Creates `style` nodes from JS strings
68 'style-loader',
69 // Translates CSS into CommonJS
70 'css-loader',
71 // Compiles Sass to CSS
72 'sass-loader',
73 ],
Aijana Schumann4bd84be2020-08-27 09:01:53 +020074 }]
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 "/oauth2/": {
144 target: "http://10.20.6.29:8181",
145 secure: false
146 },
147 "/database/": {
148 target: "http://10.20.6.29:8181",
149 secure: false
150 },
151 "/restconf/": {
152 target: "http://10.20.6.29:8181",
153 secure: false
154 },
155 "/topology/": {
156 target: "http://localhost:3001",
157 secure: false
158 },
159 "/help/": {
160 target: "http://10.20.6.29:8181",
161 secure: false
162 },
163 "/websocket/": {
164 target: "http://10.20.6.29:8181",
165 ws: true,
166 changeOrigin: true,
167 secure: false
168 }
169 }
170
171 }
172 }];
173}