源码地址:https://github.com/silence717/webpack2-demos webpack
具体可参见 demo02-entry-output 目录下git
entry
是webpack配置的入口文件的属性,也是整个项目的主入口,其他依赖的模块均在这个文件中引入。
使用方式:entry: string | Array<string>github
输出选项告诉webpack如何编写编译后的文件到磁盘。虽然能够有多个入口,可是只要一个输出配置项。
下面列举几个最主要的配置属性:web
打包后的输出目录地址,是绝对路径。ui
output: { path: __dirname + '/' }
正在研究当中,目前遇到一个dev和build环境image路径的问题,晚点具体补充。webpack2
fileName -- 指定输出文件的名称code
output: { filename: 'bundle.js' }
webpacl.config.jsget
module.exports = { entry: './index.js', output: { filename: 'bundle.js', path: __dirname + '/' } };
若是可以保证当前项目只有一个入口,咱们还能够简写为:源码
module.exports = { entry: { main: './index.js' }, output: { filename: 'bundle.js', path: __dirname + '/' } };
单个入口配置参照: demo02-entry-output/single 目录下string
若是咱们配置了多个入口那么应该使用提花布,确保每一个文件有一个惟一的名称:
[name] is replaced by the name of the chunk.
[hash] is replaced by the hash of the compilation.
[chunkhash] is replaced by the hash of the chunk.
module.exports = { entry: { indexOne: './indexOne.js', indexTwo: './indexTwo.js' }, output: { // filename: '[hash].bundle.js', filename: '[name].bundle.js', path: __dirname + '/' } };
多个入口配置参照: demo02-entry-output/multi 目录下