-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.prod.js
126 lines (124 loc) · 4.12 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
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
const webpackConstant = require('./webpack.constant');
const path = require('path');
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const WebpackCommon = require('./webpack.base');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ManifestPlugin = require('webpack-plugin-manifest');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
const DefinePlugin = webpack.DefinePlugin;
const HashedModuleIdsPlugin = webpack.HashedModuleIdsPlugin;
module.exports = webpackMerge(WebpackCommon, {
output: {
path: path.join(__dirname, webpackConstant.OutputBuildPath),
publicPath: webpackConstant.ProdPublicPath
},
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: "awesome-typescript-loader",
options: {
useBabel: false,
useCache: false, //使用babel时打开可减少编译时间
babelCore: undefined, //babel-core不在node_modules中时设置,undefined时默认在node_modules中查找babel-core
configFileName: path.join(__dirname, 'tsconfig.prod.json')
}
}
]
},
{
test: /\.html?$/,
use: [
{
loader: 'html-loader',
options: {
minimize: true
}
}
]
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [
{
loader: "css-loader"
},
{
loader: 'postcss-loader'
}
]
})
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: [
{
loader: "css-loader"
},
{
loader: "postcss-loader",
},
{
loader: "sass-loader"
}
]
})
}
]
},
plugins: [
new CleanWebpackPlugin(['dist/**', 'declaration/**'], {
root: __dirname,
verbose: true,
dry: false,
watch: true
}),
new CopyWebpackPlugin([
{
from: path.join(__dirname, webpackConstant.SrcPublicJsPath, 'webpack-dll'),
to: path.join(__dirname, webpackConstant.OutputBuildPath, webpackConstant.OutputPublicJsPath, 'webpack-dll')
}
]),
new DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new ManifestPlugin(),
new HashedModuleIdsPlugin(),
new OptimizeCssAssetsPlugin({
cssProcessorOptions: {
discardComments: {
removeAll: true
}
}
}),
new ExtractTextPlugin({
filename: path.join(webpackConstant.OutputPublicCssPath, '[name].[hash].css')
}),
new UglifyJsPlugin({
compress: {
warnings: false,
drop_console: true,
screw_ie8: true,
unsafe: true
},
beautify: false,
mangle: {
screw_ie8: true,
keep_fnames: true
},
comments: false
})
]
});