blob: 1c699e15b69d9d510430796b3df00f611f74c6e5 [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
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 apiDemo: ["./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 optimization: {
63 noEmitOnErrors: true,
64 namedModules: env !== "release",
65 minimize: env === "release",
66 minimizer: env !== "release" ? [] : [new TerserPlugin({
67 terserOptions: {
68 warnings: false, // false, true, "verbose"
69 compress: {
70 drop_console: true,
71 drop_debugger: true,
72 }
73 }
74 })],
75 },
76 plugins: [
77 // new CopyWebpackPlugin([{
78 // from: '../../../dist/**.*',
79 // to: path.resolve(__dirname, "dist")
80 // }]),
81 new webpack.DllReferencePlugin({
82 context: path.resolve(__dirname, "../../framework/src"),
83 manifest: require(path.resolve(frameworkPath, "vendor-manifest.json")),
84 sourceType: "umd2"
85 }),
86 new webpack.DllReferencePlugin({
87 context: path.resolve(__dirname, "../../framework/src"),
88 manifest: require(path.resolve(frameworkPath, "app-manifest.json")),
89 sourceType: "umd2"
90 }),
91 ...(env === "release") ? [
92 new webpack.DefinePlugin({
93 "process.env": {
94 NODE_ENV: "'production'",
95 VERSION: JSON.stringify(require("./package.json").version)
96 }
97 })
98 ] : [
99 new webpack.DefinePlugin({
100 "process.env": {
101 NODE_ENV: "'development'",
102 VERSION: JSON.stringify(require("./package.json").version)
103 }
104 }),
105 new CopyWebpackPlugin([{
106 from: 'index.html',
107 to: distPath
108 }]),
109 ]
110 ],
111
112 devServer: {
113 public: "http://localhost:3100",
114 contentBase: frameworkPath,
115
116 compress: true,
117 headers: {
118 "Access-Control-Allow-Origin": "*"
119 },
120 host: "0.0.0.0",
121 port: 3100,
122 disableHostCheck: true,
123 historyApiFallback: true,
124 inline: true,
125 hot: false,
126 quiet: false,
127 stats: {
128 colors: true
129 },
130 proxy: {
131 "/restconf/**/*": {
132 target: "https://dlux.just-run.it",
133 secure: false,
134 changeOrigin: true
135 }
136 }
137 }
138 }];
139}