gpt4 book ai didi

webpack - 具有多个入口点的动态库选项

转载 作者:行者123 更新时间:2023-12-03 22:01:09 24 4
gpt4 key购买 nike

我找到一个webpack library option with multiple entry points and UMD的示例

这是示例中的webpack.config.js:

var path = require("path");
module.exports = {
entry: {
alpha: "./alpha",
beta: "./beta"
},
output: {
path: path.join(__dirname, "js"),
filename: "MyLibrary.[name].js",
library: ["MyLibrary", "[name]"],
libraryTarget: "umd"
}
}


我的问题是如何动态配置 filenamelibrary。我想要的是:


filenamealphaa.js
filenamebetab.js
libraryalphaAlpha
library,条目 betaBeta


所以我想知道是否可以通过 function像这样配置这些选项:

var path = require("path");
module.exports = {
entry: {
alpha: "./alpha",
beta: "./beta"
},
output: {
path: path.join(__dirname, "js"),
filename: function(entryKey, entryValue) {
if (entryKey === 'alpha') return 'a.js';
if (entryKey === 'beta') return 'b.js';
},
library: function(entryKey, entryValue) {
if (entryKey === 'alpha') return 'Alpha';
if (entryKey === 'beta') return 'Beta';
},
libraryTarget: "umd"
}
}

最佳答案

从webpack 3.1.0,您可以从webpack.config.js导出多个配置

因此,您可以尝试以下操作:

  module.exports = [
{
entry: "./alpha",
output: {
path: path.join(__dirname, "js"),
filename: "a.js",
library: "Alpha",
libraryTarget: "umd"
}
},
{
entry: "./beta",
output: {
path: path.join(__dirname, "js"),
filename: "b.js",
library: "Beta",
libraryTarget: "umd"
}
},

]


相关文档: Exporting multiple configurations

关于webpack - 具有多个入口点的动态库选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34378321/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com