-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
56 lines (52 loc) · 2.02 KB
/
webpack.config.js
File metadata and controls
56 lines (52 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict'
const path = require('path');
const HelloWebpackPlugin = require('./build/CustomPlugin');
const CompilerHooks = require('./build/CompilerHooks');
const webpackMerge = require('webpack-merge');
/**
* 对于开发类库而言,必须清楚如何配置对类库的适配。其中output.library 和 ouput.libraryTarget这两个属性必须了解【https://www.xlaoyu.info/2018/01/05/webpack-output-librarytarget/】
* output.library 指定要导出库的名称
* outpur.libraryTarget 指明要导出的库适配的目标
* var : 导出一个var申明的变量
* assign : 导出一个到一个未申明的变量。默认自动挂载到全局作用域
* this : 导出运行环境的this上。如果在浏览器全局环境,等价于window
* window : 导出到window
* global : 导出到global, 适用于Node
* commonjs : 导出符合cmmonjs的模块
* commonjs2 : commonjs是导出到 exports[output.library]中 而commonjs2是直接导出到exports上,所以此时其实可以不需要output.library这个配置
* amd : 导出符合amd规范的模块
* umd : 这个最厉害,这个选项会尝试把库导出给所有的模块定义系统。umd是universal module definition的简写
*/
const targets = ['var', 'assign', 'this', 'window', 'global', 'commonjs', 'commonjs2', 'amd', 'umd', 'jsonp'];
const base = {
mode: 'none',
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, './dist')
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
include: [path.resolve(__dirname, './src')]
}
]
},
plugins: [
new HelloWebpackPlugin(),
new CompilerHooks()
],
externals: {
jquery: 'jQuery'
}
};
const targetConf = targets.map(target => webpackMerge(base, {
output: {
filename: `bundle.${target}.js`,
library: 'MyLib',
libraryTarget: target
}
}))
module.exports = base;