45 lines
994 B
JavaScript
45 lines
994 B
JavaScript
const path = require('path');
|
|
|
|
const configs = {
|
|
cjs: {
|
|
output: {
|
|
path: path.resolve(__dirname, 'dist'),
|
|
filename: 'windychen-utils.cjs.js',
|
|
libraryTarget: 'commonjs2',
|
|
},
|
|
},
|
|
esm: {
|
|
experiments: { outputModule: true },
|
|
output: {
|
|
path: path.resolve(__dirname, 'dist'),
|
|
filename: 'windychen-utils.esm.js',
|
|
libraryTarget: 'module',
|
|
},
|
|
},
|
|
umd: {
|
|
output: {
|
|
path: path.resolve(__dirname, 'dist'),
|
|
filename: 'windychen-utils.js',
|
|
library: { name: 'WindychenUtils', type: 'umd', export: 'default' },
|
|
},
|
|
},
|
|
};
|
|
|
|
module.exports = (env = {}) => {
|
|
const format = env.format;
|
|
|
|
if (!format || format === 'all') {
|
|
return Object.keys(configs).map((key) => ({
|
|
name: key,
|
|
entry: './index.js',
|
|
...configs[key],
|
|
}));
|
|
}
|
|
|
|
if (!configs[format]) {
|
|
throw new Error(`不支持的格式: ${format},可选值: cjs, esm, umd`);
|
|
}
|
|
|
|
return { entry: './index.js', ...configs[format] };
|
|
};
|