blob: b069c2a3107964a7708224cbe2d546f66958f323 [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 autoprefixer = require('autoprefixer');
12const CopyWebpackPlugin = require("copy-webpack-plugin");
13const TerserPlugin = require('terser-webpack-plugin');
14
15// const __dirname = (path => path.replace(/^([a-z]\:)/, c => c.toUpperCase()))(process.__dirname());
16
17module.exports = (env) => {
18 const distPath = path.resolve(__dirname, env === "release" ? "." : "../..", "dist");
19 const frameworkPath = path.resolve(__dirname, env === "release" ? "../../framework" : "../..", "dist");
20 return [{
21 name: "App",
22
23 mode: "none", //disable default behavior
24
25 target: "web",
26
27 context: path.resolve(__dirname, "src"),
28
29 entry: {
30 helpApp: ["./plugin.tsx"]
31 },
32
33 devtool: env === "release" ? false : "source-map",
34
35 resolve: {
36 extensions: [".ts", ".tsx", ".js", ".jsx"]
37 },
38
39 output: {
40 path: distPath,
41 filename: "[name].js",
42 library: "[name]",
43 libraryTarget: "umd2",
44 chunkFilename: "[name].js"
45 },
46 module: {
47 rules: [{
48 test: /\.tsx?$/,
49 exclude: /node_modules/,
50 use: [{
51 loader: "babel-loader"
52 }, {
53 loader: "ts-loader"
54 }]
55 }, {
56 test: /\.jsx?$/,
57 exclude: /node_modules/,
58 use: [{
59 loader: "babel-loader"
60 }]
61 }, {
62 test: /\.css$/,
63 use: [{
64 loader: 'style-loader'
65 }, {
66 loader: 'css-loader',
67 options: {
68 modules: true,
69 localIdentName: env !== "release" ? '[name]_[local]_[hash:base64:5]' : '[hash]'
70 }
71 }, {
72 loader: 'postcss-loader',
73 options: {
74 plugins: () => [autoprefixer]
75 }
76 }]
77 }]
78 },
79
80 optimization: {
81 noEmitOnErrors: true,
82 namedModules: env !== "release",
83 minimize: env === "release",
84 minimizer: env !== "release" ? [] : [new TerserPlugin({
85 terserOptions: {
86 warnings: false, // false, true, "verbose"
87 compress: {
88 drop_console: true,
89 drop_debugger: true,
90 }
91 }
92 })],
93 },
94
95 plugins: [
96 new webpack.DllReferencePlugin({
97 context: path.resolve(__dirname, "../../framework/src"),
98 manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")),
99 sourceType: "umd2"
100 }),
101 new webpack.DllReferencePlugin({
102 context: path.resolve(__dirname, "../../framework/src"),
103 manifest: require(path.resolve(frameworkPath, "app-manifest.json")),
104 sourceType: "umd2"
105 }),
Aijana Schumann1a868112022-02-01 13:18:42 +0100106 ...(env === "release" ? [
herberte6d0d672019-12-14 01:05:47 +0100107 new webpack.DefinePlugin({
108 "process.env": {
109 NODE_ENV: "'production'",
110 VERSION: JSON.stringify(require("./package.json").version)
111 }
112 }),
113 ] : [
114 new webpack.DefinePlugin({
115 "process.env": {
116 NODE_ENV: "'development'",
117 VERSION: JSON.stringify(require("./package.json").version)
118 }
119 }),
120 new CopyWebpackPlugin([{
121 from: 'index.html',
122 to: distPath
123 }]),
Aijana Schumann1a868112022-02-01 13:18:42 +0100124 ])
herberte6d0d672019-12-14 01:05:47 +0100125 ],
126 devServer: {
127 public: "http://localhost:3100",
128 contentBase: frameworkPath,
129
130 compress: true,
131 headers: {
132 "Access-Control-Allow-Origin": "*"
133 },
134 host: "0.0.0.0",
135 port: 3100,
136 disableHostCheck: true,
137 historyApiFallback: true,
138 inline: true,
139 hot: false,
140 quiet: false,
141 stats: {
142 colors: true
143 },
144 proxy: {
145 "/oauth2/": {
Michael Dürrea2b6dd32022-09-08 09:45:06 +0200146 //target: "http://10.20.6.29:48181",
147 target: "http://sdnr:8181",
herberte6d0d672019-12-14 01:05:47 +0100148 secure: false
149 },
150 "/database/": {
Michael Dürrea2b6dd32022-09-08 09:45:06 +0200151 //target: "http://10.20.6.29:48181",
152 target: "http://sdnr:8181",
herberte6d0d672019-12-14 01:05:47 +0100153 secure: false
154 },
155 "/restconf/": {
Michael Dürrea2b6dd32022-09-08 09:45:06 +0200156 //target: "http://10.20.6.29:48181",
157 target: "http://sdnr:8181",
158 secure: false
159 },
160 "/rests/": {
161 target: "http://sdnr:8181",
herberte6d0d672019-12-14 01:05:47 +0100162 secure: false
163 },
164 "/help/": {
Michael Dürrea2b6dd32022-09-08 09:45:06 +0200165 //target: "http://10.20.6.29:48181",
166 target: "http://sdnr:8181",
herberte6d0d672019-12-14 01:05:47 +0100167 secure: false
168 },
169 "/websocket/": {
Michael Dürrea2b6dd32022-09-08 09:45:06 +0200170 //target: "http://10.20.6.29:48181",
171 target: "http://sdnr:8181",
herberte6d0d672019-12-14 01:05:47 +0100172 ws: true,
173 changeOrigin: true,
174 secure: false
175 }
176 }
177 }
178 }];
179}