我有一个带有多个入口点的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 */
我切换到rollup.js,默认情况下它看起来像这样,没有任何其他配置:
// rollup.config.js
export default {
input: {
'components/index': './src/components',
'helpers/index': './src/helpers',
},
output: {
dir: 'dist',
format: 'esm',
},
};