forked from serverless-dns/serverless-dns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.fastly.cjs
59 lines (53 loc) · 1.43 KB
/
webpack.fastly.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
58
59
const webpack = require("webpack");
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
module.exports = {
entry: "./src/server-fastly.js",
target: ["webworker", "es2020"],
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: [
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: "fastly.js",
module: true,
},
externals: [
({ request }, callback) => {
// Allow Webpack to handle fastly:* namespaced module imports by treating
// them as modules rather than try to process them as URLs
if (/^fastly:.*$/.test(request)) {
return callback(null, "commonjs " + request);
}
callback();
},
],
};