blob: e44b9322b5c777ed992a8e6ea93eb700a51c732a [file] [log] [blame]
Herbert Eiselt97fa6d92019-04-03 17:12:30 +02001/**
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
14// const __dirname = (path => path.replace(/^([a-z]\:)/, c => c.toUpperCase()))(process.__dirname());
15
16module.exports = (env) => {
17 const distPath = path.resolve(__dirname, env === "release" ? "." : "../..", "dist");
18 const frameworkPath = path.resolve(__dirname, env === "release" ? "../../framework" : "../..", "dist");
19 return [{
20 name: "App",
21
22 mode: "none", //disable default behavior
23
24 target: "web",
25
26 context: path.resolve(__dirname, "src"),
27
28 entry: {
29 configurationApp: ["./plugin.tsx"]
30 },
31
32 devtool: env === "release" ? false : "source-map",
33
34 resolve: {
35 extensions: [".ts", ".tsx", ".js", ".jsx"]
36 },
37
38 output: {
39 path: distPath,
40 filename: "[name].js",
41 library: "[name]",
42 libraryTarget: "umd2",
43 chunkFilename: "[name].js"
44 },
45 module: {
46 rules: [{
47 test: /\.tsx?$/,
48 exclude: /node_modules/,
49 use: [{
50 loader: "babel-loader"
51 }, {
52 loader: "ts-loader"
53 }]
54 }, {
55 test: /\.jsx?$/,
56 exclude: /node_modules/,
57 use: [{
58 loader: "babel-loader"
59 }]
60 }]
61 },
62
63 optimization: {
64 noEmitOnErrors: true,
65 namedModules: env !== "release",
66 minimize: env === "release",
67 minimizer: env !== "release" ? [] : [new TerserPlugin({
68 terserOptions: {
69 warnings: false, // false, true, "verbose"
70 compress: {
71 drop_console: true,
72 drop_debugger: true,
73 }
74 }
75 })],
76 },
77
78 plugins: [
79 new webpack.DllReferencePlugin({
80 context: path.resolve(__dirname, "../../framework/src"),
81 manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")),
82 sourceType: "umd2"
83 }),
84 new webpack.DllReferencePlugin({
85 context: path.resolve(__dirname, "../../framework/src"),
86 manifest: require(path.resolve(frameworkPath, "app-manifest.json")),
87 sourceType: "umd2"
88 }),
89 new CopyWebpackPlugin([{
90 from: "assets",
91 to: path.resolve(distPath, "assets")
92 }]),
93 ...(env === "release") ? [
94 new webpack.DefinePlugin({
95 "process.env": {
96 NODE_ENV: "'production'",
97 VERSION: JSON.stringify(require("./package.json").version)
98 }
99 }),
100 ] : [
101 new webpack.DefinePlugin({
102 "process.env": {
103 NODE_ENV: "'development'",
104 VERSION: JSON.stringify(require("./package.json").version)
105 }
106 }),
107 new CopyWebpackPlugin([{
108 from: 'index.html',
109 to: distPath
110 }]),
111 ]
112 ],
113
114 devServer: {
115 public: "http://localhost:3100",
116 contentBase: frameworkPath,
117
118 compress: true,
119 headers: {
120 "Access-Control-Allow-Origin": "*"
121 },
122 host: "0.0.0.0",
123 port: 3100,
124 disableHostCheck: true,
125 historyApiFallback: true,
126 inline: true,
127 hot: false,
128 quiet: false,
129 stats: {
130 colors: true
131 },
132 proxy: {
133 "/oauth2/": {
134 target: "http://localhost:3000",
135 secure: false
136 },
137 "/database/": {
138 target: "http://localhost:3000",
139 secure: false
140 },
141 "/restconf/": {
142 target: "http://localhost:3000",
143 secure: false
144 },
145 "/help/": {
146 target: "http://localhost:3000",
147 secure: false
148 },
149 "/websocket/": {
150 target: "http://localhost:3000",
151 ws: true,
152 changeOrigin: true,
153 secure: false
154 }
155 }
156 }
157 }];
158}