/
pack-script.js
55 lines (49 loc) 路 1.41 KB
/
pack-script.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
import { fileURLToPath } from "url";
import path from "path";
import { writeFileSync } from "fs";
import { rollup } from "rollup";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import { babel } from "@rollup/plugin-babel";
import { terser } from "rollup-plugin-terser";
const root = fileURLToPath(path.dirname(import.meta.url));
pack("../Makefile.source.mjs", "../Makefile.js", [
"node_modules/shelljs/src/*.js",
]);
async function pack(inputPath, outputPath, dynamicRequireTargets) {
inputPath = path.join(root, inputPath);
outputPath = path.join(root, outputPath);
const bundle = await rollup({
input: inputPath,
plugins: [
nodeResolve({ preferBuiltins: true }),
commonjs({
dynamicRequireTargets: dynamicRequireTargets,
}),
babel({
babelrc: false,
babelHelpers: "bundled",
exclude: ["node_modules/core-js/**"],
parserOpts: { sourceType: "module" },
presets: [
[
"@babel/preset-env",
{
targets: { node: 6 },
useBuiltIns: "usage",
corejs: "3.23",
},
],
],
}),
terser(),
],
});
const result = await bundle.generate({
format: "cjs",
});
const output = `/* eslint-disable */
// prettier-ignore
${result.output[0].code}`;
writeFileSync(outputPath, output);
}