-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwebpack.config.cjs
115 lines (104 loc) · 2.55 KB
/
webpack.config.cjs
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* eslint-env node */
const TerserPlugin = require('terser-webpack-plugin');
const createConfig = type => {
let presetOptions = {
useBuiltIns: 'usage',
corejs: '3.38',
targets: {
esmodules: true,
},
bugfixes: true,
};
let target = 'es6';
if (type === 'modern') {
const browserslist =
'last 2 Edge versions, last 2 Safari versions, last 2 Firefox versions, last 2 Chrome versions';
presetOptions = {
useBuiltIns: 'usage',
corejs: '3.38',
targets: browserslist,
bugfixes: true,
};
target = 'browserslist:' + browserslist;
} else if (type === 'legacy') {
presetOptions = {
useBuiltIns: 'usage',
corejs: '3.38',
};
target = 'es5';
}
const entryName = type ? 'WeaponPlugin.' + type : 'WeaponPlugin';
return {
mode: 'none',
context: `${__dirname}/src/`,
devtool: 'source-map',
target,
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
include: /\.min\.js$/,
terserOptions: {
compress: true,
output: {
comments: false,
},
warnings: false,
safari10: true,
},
}),
],
},
entry: {
[entryName]: './main.ts',
[entryName + '.min']: './main.ts',
},
output: {
library: 'WeaponPlugin',
libraryTarget: 'umd',
umdNamedDefine: true,
chunkFormat: 'array-push',
},
module: {
rules: [
{
test: /.(t|j)s$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
assumptions: {
constantSuper: true,
ignoreFunctionLength: true,
ignoreToPrimitiveHint: true,
noClassCalls: true,
noDocumentAll: true,
noIncompleteNsImportDetection: true,
noNewArrows: true,
objectRestNoSymbols: true,
pureGetters: true,
setClassMethods: true,
setPublicClassFields: true,
},
presets: [
['@babel/preset-env', presetOptions],
['@babel/preset-typescript', { allowDeclareFields: true }],
],
},
},
},
],
},
resolve: {
extensions: ['.ts', '.js', '.json'],
},
externals: {
phaser: 'Phaser',
},
};
};
module.exports = [
createConfig(),
createConfig('modern'),
createConfig('legacy'),
];