I find an example of webpack library option with multiple entry points and UMD
Here is the webpack.config.js in the example:
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"
}
}
My question is how to config filename
& library
dynamically. What I want is:
filename
for entry alpha
to be a.js
filename
for entry beta
to be b.js
library
for entry alpha
to be Alpha
library
for entry beta
to be Beta
.So I wonder if I can config these options through a function
like this:
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"
}
}
From webpack 3.1.0, you can export multi configurations from webpack.config.js
So you can try the following:
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"
}
},
]
Related docs: Exporting multiple configurations
You could set the name like so
var path = require("path");
module.exports = {
entry: {
Alpha: "./alpha",
Beta: "./beta"
},
output: {
path: path.join(__dirname, "js"),
filename: '[name].js',
library: '[name]',
libraryTarget: "umd"
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With