打包组件和基础库
# 1. 如何将库暴露出去
- library: 指定库的全局变量
- libraryTarget: ⽀持库引⼊的⽅式
- libraryExport (opens new window): 指定哪一个导出应该被暴露为一个库。
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
entry: {
"large-number": "./src/index.js",
"large-number.min": "./src/index.js",
},
output: {
filename: "[name].js",
library: {
name: "largeNumber",
type: "umd",
export: "default",
umdNamedDefine: true,
},
},
mode: "none",
optimization: {
minimize: true,
minimizer: [
// 自定义压缩函数
// 通过 include 设置只压缩 min.js 结尾的⽂件
new TerserPlugin({
include: /\.min\.js$/,
}),
],
},
};