-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
71 lines (69 loc) · 1.94 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
const path = require("path");
const fs = require("fs");
const ShebangPlugin = require("webpack-shebang-plugin");
const StringReplacePlugin = require("string-replace-webpack-plugin");
module.exports = (async () => {
// https://github.com/swc-project/swc-loader/issues/56
const swcrc = await fs.readFileSync(
path.resolve(__dirname, ".swcrc"),
"utf8"
);
return {
entry: {
main: {
import: "./lib/index.ts",
filename: "index.js",
},
},
target: "node",
mode: "none",
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: "swc-loader",
options: {
...JSON.parse(swcrc),
},
},
},
{
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: StringReplacePlugin.replace({
replacements: [
{
pattern: /import {(?<promisesMethods>.+)} from (?<quotes>"|')node:fs\/promises\2(?<eol>;?\n)?/g,
replacement: function(match, p1,p2,p3, offset, string, groups) {
const { promisesMethods, quotes, eol } = groups;
return `import { promises as fspromises } from ${quotes}node:fs${quotes}${eol}const {${promisesMethods}} = fspromises;\n`;
}
}
]
}),
},
},
],
},
resolve: {
extensions: [".ts", ".js"],
},
externals: [
// rename node:<module> => module for backward compatibility with versions < node18
function ({ request }, callback) {
if (/^node:/.test(request)) {
return callback(null, `commonjs ${request.replace(/node:/, "")}`);
}
callback();
},
],
plugins: [new ShebangPlugin()],
output: {
filename: "index.js",
path: path.resolve(__dirname, "bin"),
},
};
})();