-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.conf.js
105 lines (100 loc) · 2.83 KB
/
webpack.prod.conf.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
const merge = require('webpack-merge');
const config = require('./config');
const baseWebpackConfig = require('./webpack.base.conf');
const path = require('path');
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const copyWebpackPlugin = require("copy-webpack-plugin");
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const LessFunc = require('less-plugin-functions');
function resolve (dir) {
return path.join(__dirname, '', dir)
}
module.exports = merge(baseWebpackConfig, {
mode: 'production',
output: {
path: path.resolve(__dirname, 'dist'),
filename: ('js/[name].[chunkhash].js'),
chunkFilename: ('js/[id].[chunkhash].js'),
publicPath: config.build.assetsPublicPath
},
devtool: config.build.jsSourceMap?"#source-map":false,
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: ('[name].[hash].css'),
chunkFilename: '[id].[hash].css',
// ignoreOrder: false, // Enable to remove warnings about conflicting order
// allChunks: true,
}),
// copy custom static assets
new copyWebpackPlugin([
{
from: path.resolve(__dirname, 'static'),
to: config.build.assetsSubDirectory,
ignore: ['.*']
}
]),
new UglifyJsPlugin({
uglifyOptions: {
warnings: false,
compress: {
// drop_console: true // 删除console语句
},
output: {
// comments: false,
beautify: false
}
},
sourceMap: config.build.jsSourceMap,
parallel: true
})
],
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src')]
// include: [resolve('src'), resolve('node_modules/webpack-dev-server/client')]
},
{
test: /\.less$/,
use: [{
loader: MiniCssExtractPlugin.loader,
options: {
assetsPublicPath: config.build.assetsPublicPath,
publicPath: config.build.assetsPublicPath
}
},{
loader: 'css-loader',
options: {
sourceMap: config.build.cssSourceMap
}
},config.postCssLoader, {
loader: 'less-loader',
options: {
sourceMap: config.build.cssSourceMap,
plugins: [ new LessFunc() ] // 实例化
}
}]
},
{
test: /\.css$/,
use: [{
loader: MiniCssExtractPlugin.loader,
options: {
assetsPublicPath: config.build.assetsPublicPath,
publicPath: config.build.assetsPublicPath
}
},{
loader: 'css-loader',
options: {
sourceMap: config.build.cssSourceMap
}
}, config.postCssLoader
]
}
]
}
});