blob: 70ddd493240c8b7cb0e6639e1622ef986466d2a8 [file] [log] [blame]
herberte6d0d672019-12-14 01:05:47 +01001/**
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
Michael DÜrre21e4a942021-04-08 07:27:18 +020014const policies = require('./policies.json');
15
herberte6d0d672019-12-14 01:05:47 +010016// const __dirname = (path => path.replace(/^([a-z]\:)/, c => c.toUpperCase()))(process.__dirname());
17
18module.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 connectApp: ["./pluginConnect.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 plugins: [
80 new webpack.DllReferencePlugin({
81 context: path.resolve(__dirname, "../../framework/src"),
82 manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")),
83 sourceType: "umd2"
84 }),
85 new webpack.DllReferencePlugin({
86 context: path.resolve(__dirname, "../../framework/src"),
87 manifest: require(path.resolve(frameworkPath, "app-manifest.json")),
88 sourceType: "umd2"
89 }),
90 ...(env === "release") ? [
91 new webpack.DefinePlugin({
92 "process.env": {
93 NODE_ENV: "'production'",
94 VERSION: JSON.stringify(require("./package.json").version)
95 }
96 }),
97 ] : [
98 new webpack.DefinePlugin({
99 "process.env": {
100 NODE_ENV: "'development'",
101 VERSION: JSON.stringify(require("./package.json").version)
102 }
103 }),
104 new CopyWebpackPlugin([{
105 from: 'index.html',
106 to: distPath
107 }]),
108 ]
109 ],
110
111 devServer: {
112 public: "http://localhost:3100",
113 contentBase: frameworkPath,
114
115 compress: true,
116 headers: {
117 "Access-Control-Allow-Origin": "*"
118 },
119 host: "0.0.0.0",
120 port: 3100,
121 disableHostCheck: true,
122 historyApiFallback: true,
123 inline: true,
124 hot: false,
125 quiet: false,
126 stats: {
127 colors: true
128 },
Michael DÜrre21e4a942021-04-08 07:27:18 +0200129 before: function(app, server, compiler) {
130 app.get('/oauth/policies',(_, res) => res.json(policies));
131 },
132 proxy: {
133 "/about": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100134 target: "http://sdnr:8181",
Michael DÜrre21e4a942021-04-08 07:27:18 +0200135 secure: false
136 },
137 "/yang-schema/": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100138 target: "http://sdnr:8181",
Michael DÜrre21e4a942021-04-08 07:27:18 +0200139 secure: false
140 },
141 "/oauth/": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100142 target: "http://sdnr:8181",
herberte6d0d672019-12-14 01:05:47 +0100143 secure: false
144 },
145 "/database/": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100146 target: "http://sdnr:8181",
herberte6d0d672019-12-14 01:05:47 +0100147 secure: false
148 },
Aijana Schumann85150522021-02-15 18:22:28 +0100149 "/restconf/": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100150 target: "http://sdnr:8181",
Aijana Schumann3d022712020-08-12 12:28:06 +0200151 secure: false
152 },
153 "/rests/": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100154 target: "http://sdnr:8181",
herberte6d0d672019-12-14 01:05:47 +0100155 secure: false
156 },
157 "/help/": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100158 target: "http://sdnr:8181",
Michael DÜrre21e4a942021-04-08 07:27:18 +0200159 secure: false
160 },
161 "/about/": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100162 target: "http://sdnr:8181",
Michael DÜrre21e4a942021-04-08 07:27:18 +0200163 secure: false
164 },
165 "/tree/": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100166 target: "http://sdnr:8181",
herberte6d0d672019-12-14 01:05:47 +0100167 secure: false
168 },
169 "/websocket": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100170 target: "http://sdnr:8181",
Michael DÜrre21e4a942021-04-08 07:27:18 +0200171 ws: true,
172 changeOrigin: true,
173 secure: false
174 },
175 "/apidoc": {
Aijana Schumann152cb382021-12-06 15:09:15 +0100176 target: "http://sdnr:8181",
herberte6d0d672019-12-14 01:05:47 +0100177 ws: true,
178 changeOrigin: true,
179 secure: false
180 }
181 }
182 }
183 }];
184}