Repository navigation
Expand file tree
/
Copy pathrollup.config.js
More file actions
72 lines (67 loc) · 1.5 KB
/
Copy pathrollup.config.js
File metadata and controls
72 lines (67 loc) · 1.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
import {readFileSync} from "node:fs";
import RollupNode from "@rollup/plugin-node-resolve";
import RollupTerser from "@rollup/plugin-terser";
import meta from "./package.json" with {type: "json"};
// Extract copyrights from the LICENSE.
const copyright = readFileSync("./LICENSE", "utf-8")
.split(/\n/g)
.filter(line => /^copyright\s+/i.test(line))
.map(line => line.replace(/^copyright\s+/i, ""))
.join(", ");
const banner = `// ${meta.homepage} v${meta.version} Copyright ${copyright}`;
const terser = RollupTerser({
output: {
preamble: banner
}
});
function config(options) {
return {
...options,
input: "src/index.js",
external: Object.keys(meta.dependencies || {}).filter(key => /^d3-/.test(key)),
output: {
...options.output,
name: "d3",
indent: false,
extend: true,
banner,
globals: Object.assign({}, ...Object.keys(meta.dependencies || {}).filter(key => /^d3-/.test(key)).map(key => ({[key]: "d3"})))
},
plugins: [
RollupNode(),
...(options.plugins ?? [])
]
};
}
export default [
config({
output: {
file: `dist/${meta.name}.mjs`,
format: "es"
}
}),
config({
output: {
file: `dist/${meta.name}.min.mjs`,
format: "es"
},
plugins: [
terser
]
}),
config({
output: {
file: `dist/${meta.name}.js`,
format: "umd"
}
}),
config({
output: {
file: `dist/${meta.name}.min.js`,
format: "umd"
},
plugins: [
terser
]
})
];