forked from serverless-dns/serverless-dns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.cjs
57 lines (51 loc) · 1.56 KB
/
webpack.config.cjs
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
const webpack = require("webpack");
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
// developers.cloudflare.com/workers/cli-wrangler/configuration#modules
// archive.is/FDky9
module.exports = {
entry: "./src/server-workers.js",
target: ["webworker", "es2022"],
mode: "production",
// enable devtool in development
// devtool: 'eval-cheap-module-source-map',
// gist.github.com/ef4/d2cf5672a93cf241fd47c020b9b3066a
resolve: {
fallback: {
// buffer polyfill: archive.is/7OBM7
buffer: require.resolve("buffer/"),
},
},
plugins: [
// remove "node:" prefix from imports as target is webworker
// stackoverflow.com/a/73351738 and github.com/vercel/next.js/issues/28774
// github.com/Avansai/next-multilingual/blob/aaad6a7204/src/config/index.ts#L750
new webpack.NormalModuleReplacementPlugin(/node:/, (resource) => {
resource.request = resource.request.replace(/^node:/, "");
}),
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
new webpack.IgnorePlugin({
resourceRegExp:
// eslint-disable-next-line max-len
/(^dgram$)|(^http2$)|(\/deno\/.*\.ts$)|(.*-deno\.ts$)|(.*\.deno\.ts$)|(\/node\/.*\.js$)|(.*-node\.js$)|(.*\.node\.js$)/,
}),
// stackoverflow.com/a/65556946
new NodePolyfillPlugin(),
],
optimization: {
usedExports: true,
minimize: false,
},
experiments: {
outputModule: true,
},
// stackoverflow.com/a/68916455
output: {
library: {
type: "module",
},
filename: "worker.js",
module: true,
},
};