对webpack的配置文件吐个槽
2016-08-18 17:00
337 查看
webpack官方文档
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.
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的说明看起来是详细的,但是文档中可没说,这货还可以这么省略地写,look!
假如入口文件是
除了可以省略entry的后缀,这货甚至还支持类似
也就是说可以指定默认文件,这货的默认文件就是
Ps: 感慨一下,这东西灵活归灵活,但还是建议按常规写法来,清晰明了多好呀,至少看起来一目了然。
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: 感慨一下,这东西灵活归灵活,但还是建议按常规写法来,清晰明了多好呀,至少看起来一目了然。
相关文章推荐
- webpack的配置文件为什么没起作用?
- [置顶] vue-cli的webpack模板项目配置文件分析
- webpack 配置文件解析
- 16.如何做到webpack打包vue项目后,可以修改配置文件
- webpack的配置文件
- webpack常用配置项配置文件介绍
- webpack.config.js配置文件
- vue2.0+webpack 脚手架的配置文件分析
- webpack 配置文件
- vue-cli脚手架build目录中的webpack.dev.conf.js配置文件
- vue-cli的webpack模版,相关配置文件dev-server.js与webpack.config.js配置解析
- vue-cli的webpack模板项目配置文件分析
- webpack 浅析 webpack.config.js 文件的简单配置
- 详解vue2.0脚手架的webpack 配置文件分析
- 使用webpack配置项目中的常量以及替换文件内容
- vue2.0脚手架的webpack 配置文件分析
- vue-cli的webpack模板项目配置文件分析
- vue-cli的webpack模板项目配置文件分析
- webpack 完整配置文件 Webpack2完整踩坑教程(三)
- vue-cli的webpack模板项目配置文件的理解