-
Notifications
You must be signed in to change notification settings - Fork 12
/
ncc-build.js
75 lines (72 loc) · 1.97 KB
/
ncc-build.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
72
73
74
75
import * as path from "path";
import * as fs from "fs";
import ncc from "@vercel/ncc";
ncc(path.join(import.meta.dirname, "src", "index.ts"), {
// provide a custom cache path or disable caching
cache: false,
// externals to leave as requires of the build
externals: [],
// directory outside of which never to emit assets
filterAssetBase: process.cwd(), // default
minify: false, // default
sourceMap: true, // default
sourceMapBasePrefix: "", // default treats sources as output-relative
// when outputting a sourcemap, automatically include
// source-map-support in the output file (increases output by 32kB).
sourceMapRegister: false, // default
watch: false, // default
v8cache: false, // default
quiet: false, // default
debugLog: false, // default
}).then(({ code, map, assets }) => {
const output_dir = path.join(import.meta.dirname, "lib");
fs.mkdir(
output_dir,
{
recursive: true,
mode: 0o777,
},
(err) => {
if (err) {
console.error(err.toString());
return;
}
fs.writeFile(
path.join(output_dir, "index.js"),
code,
{
encoding: "utf8",
mode: 0o777,
},
(err) => {
if (err) {
console.error(err.toString());
} else {
console.log("Written to " + path.join(output_dir, "index.js"));
}
}
);
if (map) {
fs.writeFile(
path.join(output_dir, "index.js.map"),
code,
{
encoding: "utf8",
mode: 0o777,
},
(err) => {
if (err) {
console.error(err.toString());
} else {
console.log(
"Written to " + path.join(output_dir, "index.js.map")
);
}
}
);
}
}
);
// Assets is an object of asset file names to { source, permissions, symlinks }
// expected relative to the output code (if any)
});