-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
81 lines (77 loc) · 1.96 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
const TerserPlugin = require('terser-webpack-plugin');
const path = require('path');
const pkg = require("./package.json");
const LIBRARY_NAME = pkg.name;
const PROJECT_NAME = pkg.name.replace("@", "").replace("/", "-");
const defaultConfig = env => ({
mode: env.prod ? "production" : "development",
devtool: 'source-map',
resolve: {
alias: {
typescript: false,
},
fallback: {
path: false,
fs: false,
os: false,
util: false,
stream: false,
url: false,
assert: false,
tls: false,
net: false
}
},
optimization: {
minimize: env.prod,
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
keep_classnames: true,
sourceMap: true,
}
})
],
portableRecords: true,
usedExports: true,
providedExports: true
},
performance: {
hints: false,
maxEntrypointSize: 300000,
maxAssetSize: 300000
},
});
const bundle = (env, module) => ({
name: PROJECT_NAME,
entry: `./dist/${module ? "esm" : "cjs"}/client/index.js`,
output: {
path: path.resolve(__dirname, 'dist'),
filename: `web/${PROJECT_NAME}${module ? ".es" : ""}${env.prod ? ".min" : ""}.js`,
library: module ? undefined : ['OpenHPS', LIBRARY_NAME.substring(LIBRARY_NAME.indexOf("/") + 1)],
libraryTarget: module ? "module" : "umd",
umdNamedDefine: !module,
globalObject: module ? undefined : `(typeof self !== 'undefined' ? self : this)`,
environment: { module },
},
experiments: {
outputModule: module,
},
externalsType: module ? "module" : undefined,
externals: {
'@openhps/core': module ? "./openhps-core.es" + (env.prod ? ".min" : "") + ".js" : {
commonjs: '@openhps/core',
commonjs2: '@openhps/core',
amd: 'core',
root: ['OpenHPS', 'core']
}
},
devtool: 'source-map',
plugins: [],
...defaultConfig(env)
});
module.exports = env => [
bundle(env, true),
bundle(env, false),
];