Webpack-多个入口点,它们之间需要捆绑包

问题描述 投票:0回答:1

我有一个带有多个入口点的webpack配置,看起来或多或少像这样:

const config = {
    entry: {
        'components/index': './src/components',
        'helpers/index': './src/helpers',
    },
}

module.exports = config;

这将产生两个捆绑文件:components/index.jshelpers/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
1个回答
0
投票

我切换到rollup.js,默认情况下它看起来像这样,没有任何其他配置:

// rollup.config.js

export default {
    input: {
        'components/index': './src/components',
        'helpers/index': './src/helpers',
    },
    output: {
        dir: 'dist',
        format: 'esm',
    },
};
© www.soinside.com 2019 - 2024. All rights reserved.