blob: ad5b4cc1be9781a426bfcc7b61981919f7d5f560 [file] [log] [blame]
herberte6d0d672019-12-14 01:05:47 +01001/**
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
26const path = require("path");
27const webpack = require("webpack");
28const CopyWebpackPlugin = require("copy-webpack-plugin");
29const requirejsPlugin = require('requirejs-webpack-plugin');
30const TerserPlugin = require('terser-webpack-plugin');
31
32// const __dirname = (path => path.replace(/^([a-z]\:)/, c => c.toUpperCase()))(process.__dirname());
33
34module.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 "./app.tsx",
47 "./services",
Michael Dürre7dbe38b2020-07-16 05:55:07 +020048 "./components/objectDump",
herberte6d0d672019-12-14 01:05:47 +010049 "./components/material-table",
50 "./components/material-ui",
51 "./utilities/elasticSearch",
52 "./models"],
53 },
54
55 devtool: env === "release" ? false : "source-map",
56
57 resolve: {
58 extensions: [".ts", ".tsx", ".js", ".jsx"]
59 },
60
61 output: {
62 path: distPath,
63 library: "[name]", // related to webpack.DllPlugin::name
64 libraryTarget: "umd2",
65 filename: "[name].js",
66 chunkFilename: "[name].js"
67 },
68
69 module: {
70 rules: [{
71 test: /\.tsx?$/,
72 exclude: /node_modules/,
73 use: [{
74 loader: "babel-loader"
75 }, {
76 loader: "ts-loader"
77 }]
78 }, {
79 test: /\.jsx?$/,
80 exclude: /node_modules/,
81 use: [{
82 loader: "babel-loader"
83 }]
84 }, {
85 test: /\.(png|gif|jpg|svg)$/,
86 use: [{
87 loader: 'url-loader',
88 options: {
89 limit: 10000,
90 name: './images/[hash].[ext]'
91 }
92 }]
93 }]
94 },
95
96 optimization: {
97 noEmitOnErrors: true,
98 namedModules: env !== "release",
99 minimize: env === "release",
100 minimizer: env !== "release" ? [] : [new TerserPlugin({
101 terserOptions: {
102 mangle: {
103 reserved: ["./app.tsx"]
104 },
105 warnings: false, // false, true, "verbose"
106 compress: {
107 drop_console: true,
108 drop_debugger: true,
109 }
110 }
111 })],
112 },
113
114 plugins: [
115 new CopyWebpackPlugin([{
116 from: '../../node_modules/requirejs/require.js',
117 to: '.'
118 }, {
119 from: './favicon.ico',
120 to: '.'
121 }, {
122 from: env === "release" ? './index.html' : 'index.dev.html',
123 to: './index.html'
124 }]),
125 new requirejsPlugin({
126 path: distPath,
127 filename: 'config.js',
128 baseUrl: '',
129 pathUrl: '',
130 processOutput: function (assets) {
Michael Dürre7dbe38b2020-07-16 05:55:07 +0200131 let mainConfig = JSON.stringify(assets, null, 2);
132 mainConfig = mainConfig.slice(0,-1); // remove closing bracket from string
133 const entireConfig = mainConfig.concat(", waitSeconds: 30}"); // add waitSeconds to config
134 return 'require.config(' + entireConfig + ')';
herberte6d0d672019-12-14 01:05:47 +0100135 }
136 }),
137 // new HtmlWebpackPlugin({
138 // filename: "index.html",
139 // template: "./index.html",
140 // inject: "head"
141 // }),
142 // new HtmlWebpackIncludeAssetsPlugin({
143 // assets: ['vendor.js'],
144 // append: false
145 // }),
146 new webpack.DllReferencePlugin({
147 context: path.resolve(__dirname, "src"),
148 manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")),
149 sourceType: "umd2"
150 }),
151 new webpack.DllPlugin({
152 context: path.resolve(__dirname, "src"),
153 name: "[name]",
154 path: path.resolve(distPath, "[name]-manifest.json")
155 }),
156 ...(env === "release") ? [
157 new webpack.DefinePlugin({
158 "process.env": {
159 NODE_ENV: "'production'",
160 VERSION: JSON.stringify(require("./package.json").version)
161 }
162 }),
163 ] : [
164 new webpack.HotModuleReplacementPlugin(),
165 new webpack.DefinePlugin({
166 "process.env": {
167 NODE_ENV: "'development'",
168 VERSION: JSON.stringify(require("./package.json").version)
169 }
170 }),
171 new webpack.WatchIgnorePlugin([
172 /css\.d\.ts$/,
173 /less\.d\.ts$/
Aijana Schumann4bd84be2020-08-27 09:01:53 +0200174 ]),
175 new CopyWebpackPlugin([{
176 from: './assets/version.json',
177 to: './version.json'
178 }])
herberte6d0d672019-12-14 01:05:47 +0100179 ]
180 ],
181
182 devServer: {
Aijana Schumann3d022712020-08-12 12:28:06 +0200183 public: "http://10.20.6.29:3100",
herberte6d0d672019-12-14 01:05:47 +0100184 contentBase: distPath,
185
186 compress: true,
187 headers: {
188 "Access-Control-Allow-Origin": "*"
189 },
190 host: "0.0.0.0",
191 port: 3100,
192 disableHostCheck: true,
193 historyApiFallback: true,
194 inline: true,
195 hot: false,
196 quiet: false,
197 stats: {
198 colors: true
199 },
200 proxy: {
Aijana Schumannd0fc4322020-02-12 09:08:39 +0100201 "/oauth2/": {
Aijana Schumann3d022712020-08-12 12:28:06 +0200202 target: "http://10.20.6.29:48181",
herbert05ef0232020-02-01 16:00:00 +0100203 secure: false
204 },
Aijana Schumannd0fc4322020-02-12 09:08:39 +0100205 "/database/": {
Aijana Schumann3d022712020-08-12 12:28:06 +0200206 target: "http://10.20.6.29:48181",
Aijana Schumannd0fc4322020-02-12 09:08:39 +0100207 secure: false
208 },
209 "/restconf/": {
Aijana Schumann3d022712020-08-12 12:28:06 +0200210 target: "http://10.20.6.29:48181",
Aijana Schumannd0fc4322020-02-12 09:08:39 +0100211 secure: false
212 },
213 "/help/": {
Aijana Schumann3d022712020-08-12 12:28:06 +0200214 target: "http://10.20.6.29:48181",
Aijana Schumannd0fc4322020-02-12 09:08:39 +0100215 secure: false
216 },
Aijana Schumann4bd84be2020-08-27 09:01:53 +0200217 "/about": {
218 target: "http://10.20.6.29:48181",
219 secure: false
220 },
Aijana Schumannd0fc4322020-02-12 09:08:39 +0100221 "/websocket": {
Aijana Schumann3d022712020-08-12 12:28:06 +0200222 target: "http://10.20.6.29:48181",
Aijana Schumannd0fc4322020-02-12 09:08:39 +0100223 ws: true,
224 changeOrigin: true,
herberte6d0d672019-12-14 01:05:47 +0100225 secure: false
226 }
227 }
228 }
229
230 }];
231}
232
233