webpack.production.config.js
3.8 KB
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
import path from 'path';
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import UglifyJsPlugin from 'uglifyjs-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import OptimizeCSSAssetsPlugin from 'optimize-css-assets-webpack-plugin';
import HappyPack from 'happypack';
import os from 'os';
const rootPath = path.resolve(__dirname, '..');
const happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length });
module.exports = {
entry: {
app: [path.resolve(rootPath, 'src', 'index.js')]
},
output: {
filename: '[name].[chunkhash].bundle.js',
path: path.resolve(rootPath, 'build'),
publicPath: '/'
},
module: {
rules: [{
test: /\.(js|jsx?)$/,
use: 'happypack/loader?id=jsx',
exclude: [
path.resolve(rootPath, 'node_modules')
]
}, {
test: /\.less$/,
use: 'happypack/loader?id=style'
}, {
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader"
}]
}]
},
devtool: false,//'source-map',//
cache: true,
mode: 'production',
stats: {
assets: true,
assetsSort: 'chunks',
children: false,
colors: true,
reasons: false,
hash: false,
env: true,
version: true,
timings: true,
chunks: false,
chunkGroups: false,
chunkModules: false,
chunkOrigins: false,
modules: false,
cached: false,
moduleTrace: false,
performance: true,
warnings: false,
cachedAssets: false
},
resolve: {
alias: {
src: path.resolve(rootPath, 'src')
}
},
optimization: {
minimize: false,
minimizer: [
new UglifyJsPlugin({
parallel: true,
uglifyOptions: {
compress: {
warnings: true,
drop_debugger: true,
drop_console: true
}
}
}),
new OptimizeCSSAssetsPlugin({})
]
},
plugins: [
new webpack.DefinePlugin({
"window.evn": JSON.stringify('production')
}),
new HappyPack({
id: 'jsx',
threadPool: happyThreadPool,
loaders: [{
loader: "babel-loader",
options: {
presets: ["env", "react", "stage-0"],
plugins: [["import", { "libraryName": "antd" }, "ant"]]
}
}]
}),
new HappyPack({
id: 'style',
threadPool: happyThreadPool,
loaders: [{
loader: "style-loader"
}, {
loader: "css-loader"
}, {
loader: "less-loader",
options: {
paths: [
path.resolve(rootPath, "node_modules")
]
}
}]
}),
new HtmlWebpackPlugin({
title: '小爱科技',
"filename": path.resolve(rootPath, 'build', 'index.html'),
"inject": 'body',
"template": path.resolve(rootPath, 'temp_build', 'index-production.html')
}),
new webpack.HashedModuleIdsPlugin({
hashFunction: 'sha256',
hashDigest: 'hex',
hashDigestLength: 20
}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css'
}),
new webpack.DllReferencePlugin({
context: '.',
manifest: require('../temp_build/vendor.manifest.json')
})
]
};