-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.prod.js
140 lines (139 loc) · 3.58 KB
/
webpack.config.prod.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
132
133
134
135
136
137
138
139
140
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const PurifycssWebpack = require("purifycss-webpack"); //去除无用的css
const CopyWebpackPlugin = require('copy-webpack-plugin');
const glob = require("glob"); //分析路径工具
const path = require("path");
const config = require("./webpack.config.common");
const merge = require("webpack-merge");
module.exports = merge(config, {
module: {
rules: [{
test: /\.js$/,
use: [{
loader: "babel-loader",
}],
exclude: [path.resolve(__dirname, "node_modules")]
}, {
test: /\.s?[ac]ss$/,
use: [{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: "../"
}
},
"css-loader",
"postcss-loader",
"sass-loader"
]
}, {
test: /\.(jpg|jpeg|gif|png)$/,
use: [{
loader: "file-loader",
options: {
limit: 10000,
name: "img/[name]_[hash:base64:8].[ext]",
}
}, {
loader: 'image-webpack-loader',
options: {
mozjpeg: {
progressive: true,
quality: 80
},
// optipng.enabled: false will disable optipng
optipng: {
enabled: false,
},
pngquant: {
quality: '65-90',
speed: 3
},
gifsicle: {
interlaced: false,
},
// the webp option will enable WEBP
webp: {
quality: 80
}
},
}]
}, {
test: /\.html$/,
use: ["html-loader"]
}, {
test: /\.(eot|ttf|woff|svg)$/,
use: [{
loader: "file-loader",
options: {
name: "font/[name]_[hash:base64:8].[ext]",
}
}]
}]
},
mode: "production",
plugins: [
new MiniCssExtractPlugin({
filename: "css/[name].[hash:6].css",
// chunkFilename: "css/[name].[hash:6].css",
}),
// 拷贝
// new CopyWebpackPlugin([{
// from: path.resolve(__dirname, 'src/common/js/flexible.js'),
// to: path.resolve(__dirname, 'dist/js'),
// }])
// 删除无用css
// new PurifycssWebpack({
// paths: glob.sync(path.join(__dirname, "src/page/*/*.html")),
// minimize: true,
// })
],
// 排除打包 外链引入
// externals: {
// jquery: "jQuery",
// "./src/common/js/flexible": "./src/common/js/flexible",
// },
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
}),
new OptimizeCSSAssetsPlugin({
// cssProcessor: require('cssnano'),
cssProcessor: {
process: function (css) {
return require('cssnano').process(css, { /* options */ })
.then(function (cssnanoResult) {
return require("autoprefixer").process(cssnanoResult); // Assuming mqpacker is similar to cssnano interface
});
},
canPrint: false
}
})
],
splitChunks: {
chunks: "all",
minSize: 1,
minChunks: 1,
maxAsyncRequests: 5,
maxInitialRequests: 3,
name: true,
cacheGroups: {
commons: {
name: "commons",
chunks: "all",
minChunks: 2,
filename: "js/[name].[hash:6].js"
},
styles: {
name: 'styles',
test: /\.(css|scss)$/,
chunks: 'all',
enforce: true
}
},
}
}
});