-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
121 lines (118 loc) · 3.1 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
121
const webpack = require('webpack'),
path = require('path');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const nodeExternals = require('webpack-node-externals');
const lowstats = {
stats: {
hash: false, version: false, modules: false // reduce verbosity
},
},
typescript = {
module: {
rules: [ {test: /\.tsx?$/, use: {
loader: 'ts-loader',
options: {
transpileOnly: true, /* makes it a bit faster, but suppresses type errors (use an IDE or smt) */
allowTsInNodeModules: true /* sorry, need to compile `wasi-kernel` sources as well */ }
}
} ],
},
resolve: {
extensions: [ '.tsx', '.ts', '.js' ],
}
},
shims = {
modules: {
path: 'path-browserify',
stream: 'stream-browserify',
tty: false, url: false, worker_threads: false,
fs: false, crypto: false
},
plugins: [
new webpack.DefinePlugin({process: {browser: true, env: {}, cwd: () => "/"}}),
new webpack.ProvidePlugin({Buffer: ['buffer', 'Buffer']})
]
},
dev = (argv) => ({
mode: 'development',
...(argv.mode == 'production' ? {} : {devtool: "source-map"}),
performance: {
maxEntrypointSize: 1e6, maxAssetSize: 1e6 /* sorry webpack, 244 KiB is just too small */
}
}),
out = (env, filename) => ({
output: {
filename: filename,
workerChunkLoading: false, /* does this have _any_ effect?? */
path: path.join(__dirname, env.outDir || 'dist')
}
})
module.exports = (env, argv) => [
{
name: 'cli',
target: 'node',
entry: './src/cli.ts',
...dev(argv),
...lowstats,
externalsPresets: {node: true},
externals: [nodeExternals()],
...typescript,
...out(env, 'cli.js'),
plugins: [
new webpack.BannerPlugin({banner: '#!/usr/bin/env node', raw: true}),
new webpack.optimize.LimitChunkCountPlugin({maxChunks: 1})
],
node: false
},
{
name: 'subproc',
target: 'node',
entry: './src/backend/subproc/index.ts',
...dev(argv),
...lowstats,
externalsPresets: {node: true},
externals: [nodeExternals()],
...typescript,
output: {
...out(env, 'subproc.js').output,
library: {type: 'commonjs'}
}
},
{
name: 'worker',
target: 'webworker',
entry: './src/worker.ts',
...dev(argv),
...lowstats,
...typescript,
resolve: {
...typescript.resolve,
fallback: shims.modules
},
plugins: [
...shims.plugins,
//new webpack.optimize.LimitChunkCountPlugin({maxChunks: 1}), /* breaks production build! also still creates a useless chunk for wasi-kernel's worker.ts */
//new BundleAnalyzerPlugin() /* uncomment to get size breakdown */
],
...out(env, 'worker.js')
},
{
name: 'testapp',
entry: './src/startup.ts',
...dev(argv),
...lowstats,
...typescript,
externals: { /* for subproc, only available in NWjs */
"fs": "commonjs fs",
"child_process": "commonjs2 child_process",
"byline": "commonjs2 byline",
"timers": "commonjs2 timers"
},
node: false,
resolve: {
...typescript.resolve,
fallback: shims.modules
},
...out(env, 'startup.js')
}
];