-
Notifications
You must be signed in to change notification settings - Fork 3
/
rollup.config.js
98 lines (94 loc) · 2.28 KB
/
rollup.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
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
import packageJSON from "./package.json";
import analyzer from "rollup-plugin-analyzer";
import babel from "@rollup/plugin-babel";
import commonjs from "@rollup/plugin-commonjs";
import copy from "rollup-plugin-copy";
import externals from "rollup-plugin-node-externals";
import json from "@rollup/plugin-json";
import nodeResolve from "@rollup/plugin-node-resolve";
import typescript from "rollup-plugin-typescript2";
import { generateHeader } from "./lib/header";
import { string } from "rollup-plugin-string";
const VIS_DEBUG = ["1", "true", "y", "yes"].includes(
process.env["VIS_DEBUG"] || "false"
);
const bannerModule = 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 }),
externals({ deps: true }),
copy({
targets: [
{
src: "public/*",
dest: "dist",
},
],
}),
nodeResolve({
extensions: [".css", ".html", ".js", ".json", ".ts", ".txt"],
preferBuiltins: true,
}),
string({
include: ["**/*.{css,html,txt}"],
}),
json(),
typescript({
tsconfig: "tsconfig.json",
}),
commonjs(),
babel({
babelHelpers: "runtime",
babelrc: false,
extensions: [".js", ".ts"],
include: ["src/**"],
}),
];
export default [
// JavaScript module exports.
{
input: `src/module`,
output: [
{
banner: bannerModule,
file: `dist/vis-dev-utils.cjs.js`,
format: "cjs",
sourcemap: true,
},
{
banner: bannerModule,
file: `dist/vis-dev-utils.esm.js`,
format: "esm",
sourcemap: true,
},
],
plugins: getPlugins(),
},
// File exports.
...["babel-register"].map((name) => {
return {
input: `src/${name}`,
output: {
banner: bannerCommand,
file: `${name}/index.js`,
format: "cjs",
sourcemap: true,
},
plugins: getPlugins(),
};
}),
// Node commands.
...Object.keys(packageJSON.bin).map((name) => {
return {
input: `src/${name}`,
output: {
banner: bannerCommand,
file: `bin/${name}.js`,
format: "cjs",
sourcemap: true,
},
plugins: getPlugins(),
};
}),
];