如何配置 output.library
1. 基础
2. 当 output.library 类型为 string
export function hello() {
console.log(123);
}const path = require('path');
module.exports = {
entry: path.join(__dirname, './src/foo.js'),
output: {
path: path.join(__dirname, "dist"),
filename: 'dist.js',
library: 'MyLib' // 设置了 library
},
plugins: [],
optimization: {
minimize: false // 不压缩,压缩后代码不具可读性
}
}2.1 示例 1
3. 多入口:当 output.library 类型为 string[]
4. 当 output.library 类型为 object
4.1 直接暴露一个变量
4.1.1 type: 'var'
4.1.2 type: assign
4.1.3 type: 'assign-properties'
4.2 通过给对象赋值,来暴露
4.2.1 type: this
4.2.2 type: window
4.2.3 type: global
4.2.4 type: 'commonjs'
4.3 模块系统
4.3.1 type: module, (ESM 模块)
4.3.2 type: commonjs2 (CommonJS 模块)
4.3.3 type: 'amd'
4.3.4 type: 'umd'
4.3.5 type: system 略
4.3.6 type: jsonp
5. output.library.export 的含义
6. output.library.auxiliaryComment
7. output.library.umdNamedDefine
8. 即将会过时的配置
Last updated