-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrollup.config.js
More file actions
105 lines (101 loc) · 2.5 KB
/
rollup.config.js
File metadata and controls
105 lines (101 loc) · 2.5 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import packageJSON from "./package.json" with { type: "json" };
import analyzer from "rollup-plugin-analyzer";
import esbuild from "rollup-plugin-esbuild";
import copy from "rollup-plugin-copy";
import { nodeExternals } from "rollup-plugin-node-externals";
import nodeResolve from "@rollup/plugin-node-resolve";
import { generateHeader } from "./src/module/header.ts";
const VIS_DEBUG = ["1", "true", "y", "yes"].includes(
process.env["VIS_DEBUG"] || "false",
);
/**
*
*/
export default async function () {
const bannerModule = await generateHeader();
// Shebang is necessary to execute this as a command.
const bannerCommand = "#!/usr/bin/env node\n\n" + bannerModule;
const getPlugins = () => [
analyzer(VIS_DEBUG ? undefined : { summaryOnly: true }),
nodeExternals({ deps: true }),
copy({
targets: [
{
src: "public/*",
dest: "dist",
},
],
}),
nodeResolve({
extensions: [".css", ".html", ".js", ".json", ".ts", ".txt"],
preferBuiltins: true,
}),
esbuild({
minify: false,
target: "esnext",
loaders: {
".css": "text",
".html": "text",
".json": "json",
".txt": "text",
},
}),
];
return [
// JavaScript module exports.
{
input: `src/module/index.ts`,
output: [
{
banner: bannerModule,
file: `dist/vis-dev-utils.cjs`,
format: "cjs",
sourcemap: true,
},
{
banner: bannerModule,
file: `dist/vis-dev-utils.mjs`,
format: "esm",
sourcemap: true,
},
],
plugins: getPlugins(),
},
// File exports (CJS+ESM).
...["babel-preset"].map((name) => {
return {
input: `src/${name}/index.ts`,
output: [
{
banner: bannerCommand,
file: `${name}/index.cjs`,
format: "cjs",
sourcemap: true,
},
{
banner: bannerCommand,
file: `${name}/index.mjs`,
format: "esm",
sourcemap: true,
},
],
plugins: getPlugins(),
};
}),
// Node commands.
...Object.entries(packageJSON.bin).map(([name, file]) => {
return {
input: `src/${name}/index.ts`,
output: [
{
banner: bannerCommand,
file,
format: "esm",
sourcemap: true,
},
],
plugins: getPlugins(),
};
}),
];
}