-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.prod.js
62 lines (50 loc) · 1.37 KB
/
webpack.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
const path = require('path')
// 抽取css文件
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
// 压缩js、css
const TerserJSPlugin = require('terser-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const webpack = require('webpack')
const { smart } = require('webpack-merge')
const BaseConfig = require('./webpack.base.js')
module.exports = smart(BaseConfig, {
mode: 'production',//环境
output: {//输出文件
filename: 'bundle.[hash:8].js',
path: path.resolve(__dirname, 'dist')
},
module: {
rules: [
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: 'css-loader' },
'postcss-loader',
]
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: 'css-loader' },
'postcss-loader',
'sass-loader',
]
},
]
},
plugins: [//插件
// new webpack.ProvidePlugin({//给每个模块注入jQuery
// $: 'jquery'
// }),
new MiniCssExtractPlugin({//抽离css
filename: '[name][hash:8].css',
chunkFilename: '[id][hash:8].css'
}),
new webpack.DefinePlugin({ Dev: JSON.stringify('production') })
],
optimization: {
minimizer: [new TerserJSPlugin({}), new OptimizeCSSAssetsPlugin({})],
},
})