blob: 95b5f5ed714fff268b79fb8a73d305f5a57a9a68 [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: [
Aijana Schumann85150522021-02-15 18:22:28 +010046 "./run.ts",
herberte6d0d672019-12-14 01:05:47 +010047 "./app.tsx",
48 "./services",
Michael Dürre7dbe38b2020-07-16 05:55:07 +020049 "./components/objectDump",
herberte6d0d672019-12-14 01:05:47 +010050 "./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 }]
Aijana Schumann152cb382021-12-06 15:09:15 +010085 },
86 {
Michael DÜrre0eaf2d52021-09-23 10:03:55 +020087 //don't minify images
herberte6d0d672019-12-14 01:05:47 +010088 test: /\.(png|gif|jpg|svg)$/,
89 use: [{
90 loader: 'url-loader',
91 options: {
Michael DÜrre0eaf2d52021-09-23 10:03:55 +020092 limit: 10,
93 name: './images/[name].[ext]'
herberte6d0d672019-12-14 01:05:47 +010094 }
95 }]
Aijana Schumann152cb382021-12-06 15:09:15 +010096 }
97 ]
herberte6d0d672019-12-14 01:05:47 +010098 },
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) {
Michael Dürre7dbe38b2020-07-16 05:55:07 +0200135 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 + ')';
herberte6d0d672019-12-14 01:05:47 +0100139 }
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$/
Aijana Schumann4bd84be2020-08-27 09:01:53 +0200178 ]),
179 new CopyWebpackPlugin([{
180 from: './assets/version.json',
181 to: './version.json'
182 }])
herberte6d0d672019-12-14 01:05:47 +0100183 ]
184 ],
185
186 devServer: {
Aijana Schumann85150522021-02-15 18:22:28 +0100187 public: "http://localhost:3100",
herberte6d0d672019-12-14 01:05:47 +0100188 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: {
Aijana Schumann85150522021-02-15 18:22:28 +0100205 "/about": {
206 // target: "http://10.20.6.29:48181",
Aijana Schumann152cb382021-12-06 15:09:15 +0100207 target: "http://sdnr:8181",
Aijana Schumann85150522021-02-15 18:22:28 +0100208 secure: false
209 },
210 "/yang-schema/": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100211 target: "http://sdnr:8181",
Aijana Schumann85150522021-02-15 18:22:28 +0100212 secure: false
213 },
214 "/oauth/": {
215 // target: "https://10.20.35.188:30205",
Aijana Schumann152cb382021-12-06 15:09:15 +0100216 target: "http://sdnr:8181",
Aijana Schumann85150522021-02-15 18:22:28 +0100217 secure: false
218 },
Aijana Schumannd0fc4322020-02-12 09:08:39 +0100219 "/oauth2/": {
Aijana Schumann85150522021-02-15 18:22:28 +0100220 // target: "https://10.20.35.188:30205",
Aijana Schumann152cb382021-12-06 15:09:15 +0100221 target: "http://sdnr:8181",
herbert05ef0232020-02-01 16:00:00 +0100222 secure: false
223 },
Aijana Schumannd0fc4322020-02-12 09:08:39 +0100224 "/database/": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100225 target: "http://sdnr:8181",
Aijana Schumannd0fc4322020-02-12 09:08:39 +0100226 secure: false
227 },
228 "/restconf/": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100229 target: "http://sdnr:8181",
Aijana Schumann85150522021-02-15 18:22:28 +0100230 secure: false
231 },
232 "/rests/": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100233 target: "http://sdnr:8181",
Aijana Schumannd0fc4322020-02-12 09:08:39 +0100234 secure: false
235 },
236 "/help/": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100237 target: "http://sdnr:8181",
Aijana Schumannd0fc4322020-02-12 09:08:39 +0100238 secure: false
239 },
Aijana Schumann85150522021-02-15 18:22:28 +0100240 "/about/": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100241 target: "http://sdnr:8181",
Aijana Schumann85150522021-02-15 18:22:28 +0100242 secure: false
243 },
244 "/tree/": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100245 target: "http://sdnr:8181",
Aijana Schumann4bd84be2020-08-27 09:01:53 +0200246 secure: false
247 },
Aijana Schumannd0fc4322020-02-12 09:08:39 +0100248 "/websocket": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100249 target: "http://sdnr:8181",
Aijana Schumann85150522021-02-15 18:22:28 +0100250 ws: true,
251 changeOrigin: true,
252 secure: false
253 },
254 "/apidoc": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100255 target: "http://sdnr:8181",
Aijana Schumannd0fc4322020-02-12 09:08:39 +0100256 ws: true,
257 changeOrigin: true,
herberte6d0d672019-12-14 01:05:47 +0100258 secure: false
259 }
260 }
261 }
herberte6d0d672019-12-14 01:05:47 +0100262 }];
263}
264
265