Create wt-odlux directory
[ccsdk/features.git] / sdnr / wt-odlux / odlux / framework / webpack.config.js
1 /**
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt odlux
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 /**
19  * Webpack 4 configuration file
20  * see https://webpack.js.org/configuration/
21  * see https://webpack.js.org/configuration/dev-server/
22  */
23
24 "use strict";
25
26 const path = require("path");
27 const webpack = require("webpack");
28 const CopyWebpackPlugin = require("copy-webpack-plugin");
29 const requirejsPlugin = require('requirejs-webpack-plugin');
30 const TerserPlugin = require('terser-webpack-plugin');
31
32 // const __dirname = (path => path.replace(/^([a-z]\:)/, c => c.toUpperCase()))(process.__dirname());
33
34 module.exports = (env) => {
35   const distPath = path.resolve(__dirname, env === "release" ? "." : "..", "dist");
36   const frameworkPath = path.resolve(__dirname, env === "release" ? "." : "..", "dist");
37   return [{
38     name: "Client",
39     mode: "none", //disable default behavior
40     target: "web",
41
42     context: path.resolve(__dirname, "src"),
43
44     entry: {
45       app: [
46         "./run.ts",
47         "./app.tsx",
48         "./services",
49         "./components/objectDump",
50         "./components/material-table",
51         "./components/material-ui",
52         "./utilities/elasticSearch",
53         "./models"],
54     },
55
56     devtool: env === "release" ? false : "source-map",
57
58     resolve: {
59       extensions: [".ts", ".tsx", ".js", ".jsx"]
60     },
61
62     output: {
63       path: distPath,
64       library: "[name]", // related to webpack.DllPlugin::name
65       libraryTarget: "umd2",
66       filename: "[name].js",
67       chunkFilename: "[name].js"
68     },
69
70     module: {
71       rules: [{
72         test: /\.tsx?$/,
73         exclude: /node_modules/,
74         use: [{
75           loader: "babel-loader"
76         }, {
77           loader: "ts-loader"
78         }]
79       }, {
80         test: /\.jsx?$/,
81         exclude: /node_modules/,
82         use: [{
83           loader: "babel-loader"
84         }]
85       }, 
86       {
87         //don't minify images
88         test: /\.(png|gif|jpg|svg)$/,
89         use: [{
90           loader: 'url-loader',
91           options: {
92             limit: 10,
93             name: './images/[name].[ext]'
94           }
95         }]
96       }
97       ]
98     },
99
100     optimization: {
101       noEmitOnErrors: true,
102       namedModules: env !== "release",
103       minimize: env === "release",
104       minimizer: env !== "release" ? [] : [new TerserPlugin({
105         terserOptions: {
106           mangle: {
107             reserved: ["./app.tsx"]
108           },
109           warnings: false, // false, true, "verbose"
110           compress: {
111             drop_console: true,
112             drop_debugger: true,
113           }
114         }
115       })],
116     },
117
118     plugins: [
119       new CopyWebpackPlugin([{
120         from: '../../node_modules/requirejs/require.js',
121         to: '.'
122       }, {
123         from: './favicon.ico',
124         to: '.'
125       }, {
126         from: env === "release" ? './index.html' : 'index.dev.html',
127         to: './index.html'
128       }]),
129       new requirejsPlugin({
130         path: distPath,
131         filename: 'config.js',
132         baseUrl: '',
133         pathUrl: '',
134         processOutput: function (assets) {
135           let mainConfig =  JSON.stringify(assets, null, 2);
136           mainConfig = mainConfig.slice(0,-1); // remove closing bracket from string
137           const entireConfig = mainConfig.concat(", waitSeconds: 30}"); // add waitSeconds to config
138           return 'require.config(' + entireConfig + ')';
139         }
140       }),
141       // new HtmlWebpackPlugin({
142       //   filename: "index.html",
143       //   template: "./index.html",
144       //   inject: "head"
145       // }),
146       // new HtmlWebpackIncludeAssetsPlugin({
147       //    assets: ['vendor.js'],
148       //    append: false
149       // }),
150       new webpack.DllReferencePlugin({
151         context: path.resolve(__dirname, "src"),
152         manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")),
153         sourceType: "umd2"
154       }),
155       new webpack.DllPlugin({
156         context: path.resolve(__dirname, "src"),
157         name: "[name]",
158         path: path.resolve(distPath, "[name]-manifest.json")
159       }),
160       ...(env === "release" ? [
161         new webpack.DefinePlugin({
162           "process.env": {
163             NODE_ENV: "'production'",
164             VERSION: JSON.stringify(require("./package.json").version)
165           }
166         }),
167       ] : [
168           new webpack.HotModuleReplacementPlugin(),
169           new webpack.DefinePlugin({
170             "process.env": {
171               NODE_ENV: "'development'",
172               VERSION: JSON.stringify(require("./package.json").version)
173             }
174           }),
175           new webpack.WatchIgnorePlugin([
176             /css\.d\.ts$/,
177             /less\.d\.ts$/
178           ]),
179           new CopyWebpackPlugin([{
180             from: './assets/version.json',
181             to: './version.json'
182           }])
183         ])
184     ],
185
186     devServer: {
187       public: "http://localhost:3100",
188       contentBase: distPath,
189
190       compress: true,
191       headers: {
192         "Access-Control-Allow-Origin": "*"
193       },
194       host: "0.0.0.0",
195       port: 3100,
196       disableHostCheck: true,
197       historyApiFallback: true,
198       inline: true,
199       hot: false,
200       quiet: false,
201       stats: {
202         colors: true
203       },
204       proxy: {
205         "/about": {
206           // target: "http://10.20.6.29:48181",
207           target: "http://sdnr:8181",
208           secure: false
209         }, 
210         "/yang-schema/": {
211           target: "http://sdnr:8181",
212           secure: false
213         },   
214         "/oauth/": {
215           // target: "https://10.20.35.188:30205",
216           target: "http://sdnr:8181",
217           secure: false
218         },
219         "/oauth2/": {
220           // target: "https://10.20.35.188:30205",
221           target: "http://sdnr:8181",
222           secure: false
223         },
224         "/database/": {
225           target: "http://sdnr:8181",
226           secure: false
227         },
228         "/restconf/": {
229           target: "http://sdnr:8181",
230           secure: false
231         },
232         "/rests/": {
233           target: "http://sdnr:8181",
234           secure: false
235         },
236         "/help/": {
237           target: "http://sdnr:8181",
238           secure: false
239         },
240          "/about/": {
241           target: "http://sdnr:8181",
242           secure: false
243         },
244         "/tree/": {
245           target: "http://sdnr:8181",
246           secure: false
247         },
248         "/websocket": {
249           target: "http://sdnr:8181",
250           ws: true,
251           changeOrigin: true,
252           secure: false
253         },
254         "/apidoc": {
255           target: "http://sdnr:8181",
256           ws: true,
257           changeOrigin: true,
258           secure: false
259         }
260       }
261     }
262   }];
263 }
264
265