-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.prod.js
90 lines (85 loc) · 2.87 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
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const fs = require('fs-extra');
const path = require('path');
const config = require('./webpack.config.js');
const PATH_DIST = path.join(__dirname, "dist");
const PATH_PUBLIC = path.join(__dirname, "public");
function copyPublicFolder() {
fs.emptyDirSync(PATH_DIST);
fs.copySync(PATH_PUBLIC, PATH_DIST, {
dereference: true
});
}
module.exports = function (env) {
//拷贝public到dist
copyPublicFolder();
return webpackMerge(config, {
// devtool: 'source-map',
devtool: false,
output: {
path: PATH_DIST,
filename: '[name].[chunkhash:8].js',
publicPath: '/'
},
module: {
rules: [
{
test: /\.(css|scss)$/,
use: ExtractTextPlugin.extract({
use: [
{
loader: 'css-loader',
options: {
importLoaders: 1,
sourceMap: true,
}
},
{
loader: 'postcss-loader'
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
}
},
]
})
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: './index.html',
minify: {
removeComments: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true
}
}),
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor', 'manifest']
}),
//webpack -p打出来的包会比UglifyJsPlugin小很多???
// new webpack.optimize.UglifyJsPlugin({
// compress: {
// warnings: false,
// },
// output: {
// comments: false,
// }
// }),
new ExtractTextPlugin('app.[contenthash:8].css')
],
})
}