我试图将旧的require.js grunt构建的应用程序转换为webpack。在我们当前的grunt设置中,我们构建了两个不同的bundle,并且我们有一个引导文件,我们决定在启动应用程序时需要哪个bundle。多个条目的Webpack多个resolve.alias列表
我认为在切换到webpack时应该保持这种结构。但是,当我试图配置多个条目的webpack时遇到了问题,我无法为单独的入口点提供单独的解析别名列表。我需要能够提供这些别名列表,因为我们有许多模块需要其他模块,例如require("my-module")
,并且我们在这两个bundle中都有不同的my-module
实例。
我找不到用webpack实现这个功能的方法。这可能是我被锁定在这个思维模式之中,并且看不到这个问题的另一种解决方案,因此欢迎任何建议!
这里就是我想这样做代码:
webpack.config.js
module.exports = {
entry: {
cats: ["./app/app-cats"],
dogs: ["./app/app-dogs"]
},
output: {
path: path.join(__dirname, "bin"),
filename: "[name].entry.js"
},
resolve: {
alias: {
// I would like to provide both entry points their own
// list of aliases, but currently webpack is not supporting this.
cats: {
animals: './cats.js'
},
dogs: {
animals: './dogs.js'
},
}
},
};
以下是文件的其余部分来说明我们当前的构建是如何工作的:
猫.js文件
var cats = ['dave', 'henry', 'martha'];
module.exports = cats;
dogs.js
var dogs = ['hulda', 'hilla'];
module.exports = dogs;
APP-cats.js
var animals = require('animals')
console.log(animals);
APP-dogs.js
var animals = require('animals')
console.log(animals);