-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
131 lines (126 loc) · 3.18 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const TerserWebpackPlugin = require("terser-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const autoPrefixPlugin = require("autoprefixer");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const cfg = require("./.babelrc");
const mode = process.env.NODE_ENV;
const isProd = mode === "production";
function prodOrDev(a, b) {
return isProd ? a : b;
}
const jsLoaderOptions = (isLegacy) => ({
test: /\.m?js$/,
exclude: /(node_modules\/(?!@hydrophobefireman))|(injectables)/,
use: {
loader: "babel-loader",
options: cfg.env[isLegacy ? "legacy" : "modern"],
},
});
const cssLoaderOptions = {
test: /\.css$/,
use: [
{ loader: MiniCssExtractPlugin.loader },
{
loader: "css-loader",
},
{
loader: "postcss-loader",
options: {
postcssOptions: { plugins: [autoPrefixPlugin()] },
},
},
],
};
const contentLoaderOptions = {
test: /\.(png|jpg|gif|ico|svg)$/,
use: [{ loader: "url-loader", options: { fallback: "file-loader" } }],
};
function getEnvObject(isLegacy) {
const prod = !isLegacy;
return {
arrowFunction: prod,
const: prod,
destructuring: prod,
forOf: prod,
dynamicImport: prod,
module: prod,
};
}
function getCfg(isLegacy) {
return {
cache: {
type: "filesystem",
buildDependencies: {
config: [__filename],
},
},
devServer: {
contentBase: `${__dirname}/dist`,
compress: !0,
port: 4200,
historyApiFallback: true,
},
module: {
rules: [
jsLoaderOptions(isLegacy),
cssLoaderOptions,
contentLoaderOptions,
],
},
entry: `${__dirname}/frontend/src/index.js`,
output: {
environment: getEnvObject(isLegacy),
path: `${__dirname}/dist/`,
filename: `${isLegacy ? "legacy" : "es6"}/[name]-[contenthash].js`,
},
mode,
optimization: {
concatenateModules: false,
minimizer: prodOrDev([new TerserWebpackPlugin({ parallel: true })], []),
splitChunks: {
chunks: "all",
},
runtimeChunk: "single",
},
plugins: [
new HtmlWebpackPlugin({
templateParameters: async function templateParametersGenerator(
compilation,
files,
tags,
options
) {
return {
compilation,
webpackConfig: compilation.options,
htmlWebpackPlugin: {
tags,
files,
options,
},
};
},
inject: "body",
template: `${__dirname}/frontend/index.html`,
xhtml: !0,
// favicon: "./favicon.ico",
minify: prodOrDev(
{
collapseBooleanAttributes: !0,
collapseWhitespace: !0,
html5: !0,
minifyCSS: !0,
removeEmptyAttributes: !0,
removeRedundantAttributes: !0,
},
!1
),
}),
new MiniCssExtractPlugin({}),
isProd &&
new OptimizeCSSAssetsPlugin({ cssProcessor: require("cssnano") }),
].filter(Boolean),
};
}
module.exports = getCfg(false);