-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathwebpack.config.js
58 lines (55 loc) · 1.82 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
var path = require('path')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var webpack = require('webpack')
module.exports = {
entry: {
index: ['./src/js/entry.js'], //配置两个入口
index2: ['./src/js/entry2.js']
},
output: {
path: path.resolve(__dirname, './dist/static'),
publicPath: 'static/',
filename: '[name].[chunkhash].js'
},
resolve: {
extensions: ['', '.js', '.less', '.swig', '.html']
},
module: {
loaders: [
{
test: /\.css$/,
// loader: 'style!css'
loader: ExtractTextPlugin.extract('style-loader', ['css-loader'])
},
{
test: /\.less$/,
// loader: 'style!css!less'
loader: ExtractTextPlugin.extract('style-loader', ['css-loader', 'less-loader'])
},
{
test: /\.swig/,
loader: 'swig'
}
]
},
plugins: [
new ExtractTextPlugin('[name].[chunkhash].css'),
new webpack.optimize.CommonsChunkPlugin('common.js'), //提取所有入口的公共资源,
//新的定义为common.js入口
/**
* 把chunks入口文件的资源导出到html中
* 资源可能是 css 或者 js等
* css的话 使用配合ExtractTextPlugin使用
*/
new HtmlWebpackPlugin({
chunks: ['index', 'index2', 'common.js'], //放入口文件的key即可 因为每个key对应一个输出对象js
// 这样配置话,会把index index2连个入口的输出js css都打包进html
// 再提醒一下 每个入口对应的 js css都会插入进html哦
// 必须还加入入口公共入口的部分 common 它会自动把它对应的 js css加入html
filename: '../index.html', //这个路径是相对于path
template: './src/tpl/index.html',
inject: true
})
]
}