-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
99 lines (92 loc) · 3.19 KB
/
webpack.config.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const path = require('path');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const packageJson = require('./package.json')
const isProd = process.env.NODE_ENV === 'production';
const plugins = [];
if (isProd) {
plugins.push(new UglifyJsPlugin());
}
const calcPackageName = (packageJsonName) => packageJsonName.replace("@", "").replace("/", "-");
const calcRootName = (pkgName) => pkgName.replace(/-/g, " ").replace(/\b\w/g, l => l.toUpperCase()).replace(/ /g, "");
const pkgName = calcPackageName(packageJson.name);
const rootName = calcRootName(pkgName);
const orgName = packageJson.name.indexOf("@") === 0 ? packageJson.name.split("/")[0] : undefined;
const externals = [];
if (orgName) {
externals.push(new RegExp(`^(${orgName})`));
}
module.exports = {
entry: path.resolve(__dirname, './dist/index.js'),
output: {
path: path.resolve(__dirname, './pkg'),
filename: pkgName + (isProd ? '.min' : '') + '.js',
libraryTarget: 'umd',
libraryExport: undefined,
library: {
root: rootName,
amd: packageJson.name,
commonjs: packageJson.name
},
umdNamedDefine: true,
globalObject: 'typeof self !== \'undefined\' ? self : this'
},
target: "web",
externals,
mode: isProd ? "production" : "development",
devtool: isProd ? undefined : "inline-source-map",
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
"presets": [
[
"@babel/preset-env", {
"targets": {
"browsers": [
"Chrome >= 52",
"FireFox >= 44",
"Safari >= 7",
"Explorer 11",
"last 4 Edge versions"
]
}
}
]
],
"plugins": [
[
"@babel/plugin-transform-runtime",
{
"helpers": false,
"regenerator": true
}
],
[
"babel-plugin-transform-builtin-extend",
{
"globals": ["Error"]
}
]
]
}
}
}
]
},
node: {
fs: "empty",
path: "empty",
console: false,
global: false,
process: false,
__filename: false,
__dirname: false,
Buffer: false,
setImmediate: false
},
plugins
};