-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrollup.config.js
More file actions
108 lines (97 loc) · 2.33 KB
/
rollup.config.js
File metadata and controls
108 lines (97 loc) · 2.33 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
106
107
108
import { readFileSync } from "fs";
import json from "@rollup/plugin-json";
import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";
import { nodeResolve } from "@rollup/plugin-node-resolve";
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+/.test(line))
.map((line) => line.replace(/^Copyright\s+/, ""))
.join(", ");
// Create banner text once
const BANNER = `// ${meta.name} v${meta.version} Copyright ${copyright}`;
// Base globals configuration
const globals = {
"d3-scale": "d3",
...Object.assign(
{},
...Object.keys(meta.dependencies || {})
.filter((key) => /^d3-/.test(key))
.map((key) => ({ [key]: "d3" })),
),
};
// Base external dependencies
const external = ["d3-scale"];
// Base configuration shared across all builds
const baseConfig = {
input: "src/index.ts",
output: {
name: "d3",
extend: true,
banner: BANNER,
sourcemap: true,
},
};
// ES module for npm (with external dependencies)
const esmConfig = {
...baseConfig,
external,
output: {
...baseConfig.output,
file: "dist/d3-ternary.js",
format: "es",
globals,
},
plugins: [typescript(), json()],
};
// ES module for browser (bundled dependencies)
const esmBrowserConfig = {
...baseConfig,
external: [],
output: {
...baseConfig.output,
file: "dist/d3-ternary.bundle.js",
format: "es",
},
plugins: [nodeResolve(), typescript()],
};
// UMD module
const umdConfig = {
...baseConfig,
external,
output: {
...baseConfig.output,
file: "dist/d3-ternary.umd.js",
format: "umd",
globals,
},
plugins: [typescript()],
};
// Helper function to create minified config
const createMinifiedConfig = (config, suffix) => ({
...config,
output: {
...config.output,
file: config.output.file.replace(".js", suffix),
},
plugins: [
...config.plugins,
terser({
output: {
preamble: BANNER,
},
}),
],
});
// Create minified versions
const minifiedConfig = createMinifiedConfig(esmConfig, ".min.js");
const minifiedUmdConfig = createMinifiedConfig(umdConfig, ".min.js");
export default [
esmConfig,
esmBrowserConfig,
umdConfig,
minifiedUmdConfig,
minifiedConfig,
];