您的位置:首页 > Web前端 > Webpack

对webpack的配置文件吐个槽

2016-08-18 17:00 337 查看
webpack官方文档


entry

The entry point for the bundle.

If you pass a string: The string is resolved to a module which is loaded upon startup.

If you pass an array: All modules are loaded upon startup. The last one is exported.

entry: ["./entry1", "./entry2"]

If you pass an object: Multiple entry bundles are created. The key is the chunk name. The value can be a string or an array.

{
entry: {
page1: "./page1",
page2: ["./entry1", "./entry2"]
},
output: {
// Make sure to use [name] or [id] in output.filename
//  when using multiple entry points
filename: "[name].bundle.js",
chunkFilename: "[id].bundle.js"
}
}


文档中对entry的说明看起来是详细的,但是文档中可没说,这货还可以这么省略地写,look!

假如入口文件是
src/index.js
,那么在
webpack.config.js
中就可以这么写:

// String
{
entry: './src/index.js',
output: {
path: './dist',
filename: '[name].bundle.js'
}
}

// 或者不指定entry的文件后缀也是可以的
{
entry: './src/index',
output: {
path: './dist',
filename: '[name].bundle.js'
}
}

除了可以省略entry的后缀,这货甚至还支持类似
apache
nginx
DirectoryIndex


也就是说可以指定默认文件,这货的默认文件就是
index.js
。对应的配置就可以写成下面这样了:

{
entry: './src',
output: {
path: './dist',
filename: '[name].bundle.js'
}
}

Ps: 感慨一下,这东西灵活归灵活,但还是建议按常规写法来,清晰明了多好呀,至少看起来一目了然。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: