-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.production.config.js
52 lines (51 loc) · 1.78 KB
/
webpack.production.config.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
// TODOS:重新配置入口文件及输出路径
const path = require('path')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
entry: path.join(__dirname, 'src/public/scripts/index.es'),
output: {
path: path.join( __dirname, '/build/public'), // 打包后的文件存放的地方
filename: 'scripts/[name]-[hash:5].js', // 打包后输出文件的文件名,带有md5 hash戳
publicPath: '/'
},
module: {
rules: [{
test: /(\.jsx|\.js|\.es)$/,
use: {
loader: 'babel-loader'
},
exclude: /node_modules/ // 不进行编译的目录
}, {
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: {
loader: 'css-loader',
options: {
minimize: true
}
}
})
}]
},
plugins: [
new HtmlWebpackPlugin({
filename: '../views/index.html',
template: path.join( __dirname, 'src/views/index.html') // new 一个这个插件的实例,并传入相关的参数
}),
new ExtractTextPlugin('styles/style-[hash:5].css'),
new CleanWebpackPlugin(['build/public/*', 'build/views/*'], {
root: __dirname,
verbose: true,
dry: false
}),
new webpack.optimize.UglifyJsPlugin(),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'scripts/common/vendor-[hash:5].js'
}),
]
}