forked from BNDong/Cnblogs-Theme-SimpleMemory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
95 lines (93 loc) · 2.56 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
const path = require('path');
const json5 = require('json5');
const terserPlugin = require("terser-webpack-plugin");
const fileManagerPlugin = require('filemanager-webpack-plugin');
const miniCssExtractPlugin = require('mini-css-extract-plugin');
const cssMinimizerPlugin = require('css-minimizer-webpack-plugin');
/**
* 随机字符串
* @param len
* @returns {string}
*/
function randomString(len) {
len = len || 32;
let $chars = 'abcdefhijkmnprstwxyz23456789';
let maxPos = $chars.length;
let pwd = '';
for (let i = 0; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
module.exports = {
mode: 'development',
entry: './src/main.js',
output: {
filename: 'simpleMemory.js',
chunkFilename:'script/[name].[hash:8].js',
path: path.resolve(__dirname, 'dist'),
clean: true,
},
plugins: [
new fileManagerPlugin({
events: {
onEnd: {
copy: [
{ source: './dist/simpleMemory.js', destination: './dist/simpleMemory.' + randomString(8) + '.js' },
],
}
}
}),
new miniCssExtractPlugin({
filename: 'style/[name].[hash:8].css',
chunkFilename:'style/[name].[hash:8].css',
}),
],
// devtool: 'inline-source-map',
optimization: {
minimize: true,
minimizer: [
new terserPlugin({
extractComments: false,
}),
new cssMinimizerPlugin(),
],
},
module: {
rules: [
{
test: /\.css$/i,
use: [
{
loader: miniCssExtractPlugin.loader,
options: {
publicPath: '../'
}
},
'css-loader'
],
},
{
test: /\.(png|svg|jpg|jpeg|gif|webp)$/i,
type: 'asset/resource',
generator: {
filename: 'images/[hash][ext][query]'
}
},
{
test: /\.json5$/i,
type: 'json',
parser: {
parse: json5.parse,
},
},
{
test: /\.html$/i,
loader: 'html-loader',
options: {
minimize: true,
},
},
],
},
};