-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebpack.config.js
86 lines (86 loc) · 2.22 KB
/
webpack.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
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
var htmlWebpackPlugin=require('html-webpack-plugin');
var webpack=require('webpack');
var path=require('path');
module.exports={
entry:{
main:'./src/app.js',
vendor:['react', 'react-dom']
},
output:{
path:path.resolve(__dirname,'dist'),
filename:'js/[name].bundle.js',
publicPath: '/'
},
module:{
loaders:[
{
test:/\.js$/,
loader:'babel-loader',
exclude:path.resolve(__dirname,'node_modules'),
include:path.resolve(__dirname,'src'),
query:{
presets:['latest','stage-0', 'react']
}
},{
test:/\.tpl$/,
loader:'ejs-loader'
},
{
test:/\.css$/,
loader:'style-loader!css-loader?importLoaders=1!postcss-loader'
},{
test:/\.less$/,
loader:'style-loader!css-loader!postcss-loader!less-loader'
},{
test:/\.scss$/,
loader:'style-loader!css-loader!postcss-loader!sass-loader'
},{
test:/\.html$/,
loader:'html-loader'
},{
test:/\.(png|jpg|gif|svg)$/i,
loader:'file-loader',
query:{
name:'assets/[name]-[hash].[ext]'
}
},{
test: /\.(woff|woff2|eot|ttf|otf)$/,
loader:'file-loader',
query:{
name:'assets/[name]-[hash].[ext]'
}
},{
test: /\.(csv|tsv)$/,
loader:'csv-loader',
query:{
name:'assets/[name]-[hash].[ext]'
}
},{
test: /\.xml$/,
loader:'xml-loader',
query:{
name:'assets/[name]-[hash].[ext]'
}
}
]
},
devServer:{
hot:true,
contentBase:path.resolve(__dirname,'dist'),
publicPath:'/',//载入热更新模块,并且需要在插件中使用HMR
},
plugins:[
new webpack.optimize.CommonsChunkPlugin({
name:'vendor', filename:'vendor.bundle.js'
}),//公用的一些库js
new htmlWebpackPlugin({
filename:'index.html',
template:'index.html',
inject:'body',
title:'webpack demo'
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),//当模块热替换(HMR)时在浏览器控制台输出对用户更友好的模块名字信息
],
devtool:"inline-source-map"
}