blob: fdae7d9578bd90a1c40a84ef5e6749d63117ea27 [file] [log] [blame]
Herbert Eiselt3d202a02019-02-11 14:54:12 +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 }),
106 ...(env === "release") ? [
107 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 }]),
124 ]
125 ],
126
127 devServer: {
128 public: "http://localhost:3100",
129 contentBase: frameworkPath,
130
131 compress: true,
132 headers: {
133 "Access-Control-Allow-Origin": "*"
134 },
135 host: "0.0.0.0",
136 port: 3100,
137 disableHostCheck: true,
138 historyApiFallback: true,
139 inline: true,
140 hot: false,
141 quiet: false,
142 stats: {
143 colors: true
144 },
145 proxy: {
146 "/help": {
147 target: "http://localhost:8181",
148 secure: false
149 }
150 }
151 }
152 }];
153}