-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
99 lines (97 loc) · 2.88 KB
/
webpack.config.js
File metadata and controls
99 lines (97 loc) · 2.88 KB
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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const WebpackObfuscator = require('webpack-obfuscator');
const webpack = require('webpack');
const isProd = process.env.NODE_ENV === 'production';
const includeTools = process.env.INCLUDE_TOOLS === '1' || !isProd;
module.exports = {
mode: isProd ? 'production' : 'development',
target: ['web', 'es5'],
entry: {
app: path.resolve(__dirname, 'public', 'app.entry.js'),
},
output: {
path: path.resolve(__dirname, 'dist', 'public'),
filename: isProd ? '[name].[contenthash].js' : '[name].js',
assetModuleFilename: 'assets/[name][ext]'
},
module: {
rules: [
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.(png|jpe?g|gif|svg|ico)$/i,
type: 'asset/resource',
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'public', 'index.template.html'),
templateParameters: { includeTools },
minify: {
removeComments: true,
collapseWhitespace: true,
keepClosingSlash: true,
removeRedundantAttributes: true,
removeEmptyAttributes: true,
},
}),
new webpack.DefinePlugin({
__INCLUDE_TOOLS__: JSON.stringify(includeTools),
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || (isProd ? 'production' : 'development')),
}),
new MiniCssExtractPlugin({ filename: isProd ? '[name].[contenthash].css' : '[name].css' }),
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(__dirname, 'public'),
to: '.',
globOptions: { ignore: ['**/index.html', '**/index.template.html', '**/app.js', '**/app.entry.js', '**/styles.css', '**/js/**/*.js'] },
noErrorOnMissing: true,
},
],
}),
...(isProd
? [
new WebpackObfuscator(
{
compact: true,
rotateStringArray: true,
stringArray: true,
stringArrayThreshold: 0.75,
deadCodeInjection: false,
controlFlowFlattening: false,
disableConsoleOutput: true,
},
[]
),
]
: []),
],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
compress: {
drop_console: true,
passes: 2,
},
mangle: true,
format: { comments: false },
},
}),
new CssMinimizerPlugin(),
],
},
devtool: false,
performance: { hints: false },
};