简体   繁体   English

Webpack多个文件条目包

[英]Webpack multiple files entry bundle

Will webpack produce different results given a configuration like so: 给定这样的配置,webpack会产生不同的结果:

// webpack.config.js
module.exports = {
    ...
    entry: {
        main: ['./index.js'],
    }
}


// index.js
import 'babel-polyfill'
...

vs.

// webpack.config.js
module.exports = {
    ...
    entry: {
        main: ['babel-polyfill', './index.js'],
    }
}


// index.js
// babel-polyfill import removed
...

Which one is preferred, and why? 首选哪一个,为什么?

Both works kind of the same way. 两者的工作方式相同。 The option 1, webpack would treat babel-polyfill as a dependency, in the dependency tree. 选项1,webpack将在依赖关系树中将babel-polyfill polyfill视为依赖项。

The second one, webpack would treat babel-polyfill as an entrypoint, where it would try to generate a dependency graph from that, which would have 0 dependencies. 第二个,webpack将babel-polyfill polyfill作为入口点,它将尝试从中生成一个依赖关系图,该关系图将具有0个依赖关系。

There is no real difference here, nor any impact on the result bundle, both will contain babel-polyfill anyways, and also there is no "preferred" way to add that, babel itself refeers to both ways on their guide. 这里没有真正的区别,也没有对结果包产生任何影响,无论如何都将包含babel-polyfill,也没有添加“首选”方法,babel本身在其指南中倾向于这两种方法。

The result will be the same. 结果将是相同的。 It depends on you, usually I prefer to import the dependencies in modules rather than importing implicitly in webpack config. 这取决于您,通常我更喜欢在模块中导入依赖项,而不是在webpack配置中隐式导入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM