-
Notifications
You must be signed in to change notification settings - Fork 406
Expand file tree
/
Copy pathrspack.config.js
More file actions
99 lines (93 loc) · 3.42 KB
/
Copy pathrspack.config.js
File metadata and controls
99 lines (93 loc) · 3.42 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
'use strict'
// TODO: Stop depending on `@opentelemetry/api` and instead intercept the user
// version with an instrumentation.
// TODO: Stop depending on `@openfeature/server-sdk` and `@openfeature/core` and
// instead intercept the user version with an instrumentation.
// TODO: Vendor `@datadog/openfeature-node-server` when the above has been
// addressed.
// TODO: Fix `import-in-the-middle` so that it doesn't interfere with the global
// object or switch to our own internal loader and remove the dependency.
// TODO: Vendor `dc-polyfill` and figure out why it fails the tests.
const { CopyRspackPlugin, SwcJsMinimizerRspackPlugin } = require('@rspack/core')
const { LicenseWebpackPlugin } = require('license-webpack-plugin')
const { join } = require('path')
const { dependencies } = require('./package.json')
const include = new Set([
...Object.keys(dependencies),
'mutexify/promise',
'protobufjs/minimal', // peer dependency for `@datadog/sketches-js`
'source-map/lib/util' // TODO: remove usage of dependency internals
])
const exclude = new Set([
'mutexify' // we only ever use `mutexify/promise`
])
const difference = new Set([...include].filter(x => !exclude.has(x)))
module.exports = {
entry: Object.fromEntries(difference.entries()),
target: 'node',
mode: 'production',
// Using `hidden` removes the URL comment from source files since we don't
// publish the maps that the comments would be referencing. Since the maps
// have the same filename as the source files this doesn't matter anyway.
devtool: 'hidden-source-map',
context: join(__dirname, 'node_modules'),
resolve: {
// Node.js does not use the `module` field, so prefer `main` (CJS) to avoid
// ESM-only default exports being wrapped in a namespace by rspack's interop,
// which would break patterns like `require('esquery').parse`.
mainFields: ['main', 'module'],
},
optimization: {
// Here we used `named` instead of the default of `deterministic` since the
// default is only deterministic with the same dependencies, but when a
// dependency is added it would change the IDs of other ones resulting in
// unnecessary noise.
checkIds: 'named',
moduleIds: 'named',
minimizer: [
new SwcJsMinimizerRspackPlugin({
minimizerOptions: {
mangle: {
// Similar to the above, we configure the minimizer to keep the
// original names. In this case it's also useful at runtime when
// checking the value of the name, or for stack traces when the
// source maps are not used.
keepClassNames: true,
keepFnNames: true,
},
},
}),
],
},
// These are shared between dd-trace and users, so they need to be external.
externals: {
'@opentelemetry/api': '@opentelemetry/api'
},
plugins: [
new LicenseWebpackPlugin({
outputFilename: '[name]/LICENSE',
excludedPackageTest: packageName => !include.has(packageName),
renderLicenses: modules => modules[0].licenseText,
stats: {
warnings: false
}
}),
new CopyRspackPlugin({
patterns: [
// Binaries need to be copied manually.
{
from: 'source-map/lib/mappings.wasm',
to: 'source-map'
},
],
}),
],
output: {
filename: '[name]/index.js',
library: {
type: 'commonjs2'
},
path: join(__dirname, 'dist'),
clean: true
},
}