【发布时间】:2020-05-04 14:33:13
【问题描述】:
我有一个带有多个入口点的 webpack 配置,看起来或多或少像这样:
const config = {
entry: {
'components/index': './src/components',
'helpers/index': './src/helpers',
},
}
module.exports = config;
这会生成两个捆绑文件:components/index.js 和 helpers/index.js。这很好,但问题是components/index.js 包含来自helpers 的整个代码...这是因为组件正在导入辅助函数。
例子:
-
src/helpers导出名为foo的函数。 -
src/components从助手导入foo函数。
现在,在 components/index.js 包中,我看到声明了 foo 函数。有没有办法告诉 webpack 它应该使用 require() 函数并导入这个 foo 函数?
所以component/index.js 的输出看起来像这样:
var foo = require('../helpers/index.js')
/* rest of the code */
【问题讨论】:
标签: javascript webpack bundler rollup