-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.common.config.js
More file actions
78 lines (72 loc) · 2.44 KB
/
webpack.common.config.js
File metadata and controls
78 lines (72 loc) · 2.44 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
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
/*入口*/
entry: {
app: [
"babel-polyfill",
path.join(__dirname, 'src/index.js')
],
vendor: ['react', 'react-router-dom', 'redux', 'react-dom', 'react-redux']
},
/*输出到dist文件夹,输出文件名字为bundle.js*/
output: {
path: path.join(__dirname, './dist'),
filename: '[name].[chunkhash].js',
chunkFilename: '[name].[chunkhash].js',
publicPath : '/'//静态文件的链接定位到静态服务器,相当于绝对路径
},
/*src文件夹下面的以.js结尾的文件,要使用babel解析*/
/*cacheDirectory是用来缓存编译结果,下次编译加速*/
module: {
rules: [{
test: /\.js$/,
use: ['babel-loader?cacheDirectory=true'],
include: path.join(__dirname, 'src')
},{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},{
test: /\.(png|jpg|gif)$/,
use: [{
loader: 'url-loader',
options: {
limit: 8192
}
}]
},{
test: /\.(woff|woff2|svg|ttf|eot)($|\?)/i,
use: [{
loader: 'url-loader',
options: {
limit: 5000 // 限制大小5kb
}
}]
}]
},
/*插件配置*/
plugins: [
new HtmlWebpackPlugin({//用于加载增加了hash值的js文件到html
filename: 'index.html',
template: path.join(__dirname, 'src/index.html')
}),
new webpack.optimize.CommonsChunkPlugin({//用于提取react redux等公共组件
name: 'vendor'
}),
new webpack.HashedModuleIdsPlugin(),//用于保证vendor后的hash部分不变化
new webpack.optimize.CommonsChunkPlugin({//用于保证vendor后的hash部分不变化
name: 'runtime'
})
],
/*别名配置*/
resolve: {
alias: {
pages: path.join(__dirname, 'src/pages'),
components: path.join(__dirname, 'src/components'),
router: path.join(__dirname, 'src/router'),
actions: path.join(__dirname, 'src/redux/actions'),
reducers: path.join(__dirname, 'src/redux/reducers')
}
}
}