-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
120 lines (116 loc) · 3.34 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const TerserPlugin = require('terser-webpack-plugin');
const InjectPlugin = require('webpack-inject-plugin').default;
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,
'threads/observable': path.join(__dirname, "node_modules", '/threads/observable.js'),
'threads': path.join(__dirname, "node_modules", '/threads/dist/index.js'),
},
fallback: {
path: false,
fs: false,
os: 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/esm5/index.js`,
output: {
path: path.resolve(__dirname, 'dist'),
filename: `web/${PROJECT_NAME}${module ? ".es" : ""}${env.prod ? ".min" : ""}.js`,
library: module ? undefined : ['OpenHPS', 'core'],
libraryTarget: module ? "module" : "umd",
umdNamedDefine: !module,
globalObject: module ? undefined : `(typeof self !== 'undefined' ? self : this)`,
},
experiments: {
outputModule: module,
},
externals: [],
plugins: [],
...defaultConfig(env)
});
module.exports = env => [
bundle(env, true),
bundle(env, false),
{
name:`${PROJECT_NAME}-worker`,
entry: `./dist/cjs/worker/WorkerRunner.js`,
externals: {'..': LIBRARY_NAME},
output: {
path: path.resolve(__dirname, 'dist'),
filename: `web/worker.${PROJECT_NAME}${env.prod ? ".min" : ""}.js`,
libraryTarget: 'umd',
umdNamedDefine: true,
globalObject: `(typeof self !== 'undefined' ? self : this)`,
},
plugins: [
new InjectPlugin(function() {
return `importScripts('${PROJECT_NAME}${env.prod ? ".min" : ""}.js'); __WEBPACK_EXTERNAL_MODULE____ = self.OpenHPS.core;`
})
],
...defaultConfig(env)
},
{
name:`${PROJECT_NAME}-worker`,
entry: `./dist/esm5/worker/WorkerRunner.js`,
output: {
path: path.resolve(__dirname, 'dist'),
filename: `web/worker.${PROJECT_NAME}.es${env.prod ? ".min" : ""}.js`,
libraryTarget: 'module',
umdNamedDefine: false,
},
externals: {'..': `./openhps-core.es${env.prod ? ".min" : ""}.js`},
plugins: [],
experiments: {
outputModule: true,
},
...defaultConfig(env)
},
{
name: PROJECT_NAME,
entry: `./dist/esm5/index.lite.js`,
output: {
path: path.resolve(__dirname, 'dist'),
filename: `web/${PROJECT_NAME}-lite${env.prod ? ".min" : ""}.js`,
library: ['OpenHPS', 'core'],
libraryTarget: "umd",
umdNamedDefine: true,
globalObject: `(typeof self !== 'undefined' ? self : this)`,
},
experiments: {
outputModule: false,
},
externals: [],
plugins: [],
...defaultConfig(env)
}
];