-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathrspack.config.js
More file actions
146 lines (142 loc) · 5.71 KB
/
rspack.config.js
File metadata and controls
146 lines (142 loc) · 5.71 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const rspack = require('@rspack/core');
const path = require('path');
const { sentryWebpackPlugin } = require('@sentry/webpack-plugin');
const pjson = require('./package.json');
const OUTPUT_DIR = path.resolve(__dirname, 'bundle');
console.log(
process.env.SENTRY_AUTH_TOKEN
? "* Rspack will upload source map to Sentry *"
: "Sentry source map upload disabled - no token set"
);
module.exports = {
entry: {
index: './src/index.ts',
'error-tracking': './src/error-tracking.ts'
},
output: {
path: OUTPUT_DIR,
filename: '[name].js',
libraryTarget: 'commonjs2'
},
mode: 'production',
devtool: 'source-map',
target: 'node',
node: false, // Don't mess with any node built-ins or globals
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'builtin:swc-loader',
options: {
jsc: {
parser: {
syntax: 'typescript',
decorators: true
},
transform: {
decoratorVersion: '2022-03'
}
}
}
},
{
// Required to build .mjs files correctly
test: /\.mjs$/,
include: /node_modules/,
type: "javascript/auto",
},
{
test: /node_modules[\\|/]simple-plist[\\|/]dist/,
use: { loader: 'umd-compat-loader' }
},
{
// Some browser launchers (Opera) use resource files from within the browser-launcher
// module. We need to reroute that to point to the unbundled files:
test: /node_modules\/@httptoolkit\/browser-launcher\/dist\/run.js$/,
loader: 'string-replace-loader',
options: {
search: '../res/',
replace: './bl-resources/',
flags: 'g',
strict: true
}
}
]
},
externals: [
'@oclif/plugin-update/lib/commands/update', // Lots of complicated dynamic requires in @oclif
'registry-js', // Native module
'win-version-info', // Native module
'node-datachannel', // Native module
'_stream_wrap', // Used in httpolyglot only in old Node, where it's available
function ({ context, request }, callback) {
if (context !== __dirname && request.endsWith('/error-tracking')) {
// Direct all requires of error-tracking to its entrypoint at the top level,
// except the root require that actually builds the entrypoint.
callback(null, 'commonjs ./error-tracking');
} else {
callback();
}
}
],
plugins: [
// Convert ESM import.meta.dirname/filename to CommonJS equivalents.
// Required because @httptoolkit/browser-launcher is ESM and uses import.meta.dirname,
// but we output CommonJS where import.meta isn't available.
new rspack.DefinePlugin({
'import.meta.dirname': '__dirname',
'import.meta.filename': '__filename'
}),
// Optimistic require for 'iconv' in 'encoding', falls back to 'iconv-lite'
new rspack.NormalModuleReplacementPlugin(/\/iconv-loader$/, 'node-noop'),
// Optimistically required in (various) ws versions, with fallback
new rspack.IgnorePlugin({ resourceRegExp: /^bufferutil$/ }),
// Optimistically required in (various) ws versions, with fallback
new rspack.IgnorePlugin({ resourceRegExp: /^utf-8-validate$/ }),
// Optimistically required in headless, falls back to child_process
new rspack.IgnorePlugin({ resourceRegExp: /^child-killer$/ }),
// GraphQL playground - never used
new rspack.NormalModuleReplacementPlugin(/^\.\/renderGraphiQL$/, 'node-noop'),
// SSH2 - used within Dockerode, but we don't support it and it has awkward native deps
new rspack.NormalModuleReplacementPlugin(/^ssh2$/, 'node-noop'),
// CDP protocol - not used without local:true (which we never use, we always
// get the CDP protocol details from the target Electron app).
new rspack.IgnorePlugin({
resourceRegExp: /^\.\/protocol.json$/,
contextRegExp: /chrome-remote-interface/
}),
// Copy browser launcher's static resources into the output directory
new rspack.CopyRspackPlugin({
patterns: [{
from: path.join('node_modules', '@httptoolkit', 'browser-launcher', 'res'),
to: 'bl-resources'
}]
}),
// If SENTRY_AUTH_TOKEN is set, upload this sourcemap to Sentry
process.env.SENTRY_AUTH_TOKEN
? sentryWebpackPlugin({
org: 'http-toolkit',
project: 'httptoolkit-server',
release: { name: pjson.version },
sourcemaps: { assets: [`${OUTPUT_DIR}/**`] },
urlPrefix: '~/bundle',
validate: true
})
: { apply: () => {} },
// Used to e.g. fix the relative path to the overrides directory
new rspack.EnvironmentPlugin({ HTK_IS_BUNDLED: true })
],
resolve: {
extensions: [ '.tsx', '.ts', '.mjs', '.js' ]
},
optimization: {
minimizer: [
new rspack.SwcJsMinimizerRspackPlugin({
minimizerOptions: {
module: true // Treat as ES module to allow import.meta
}
})
]
}
};