-
Notifications
You must be signed in to change notification settings - Fork 3
/
rollup.config.js
76 lines (69 loc) · 1.76 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
import {readFileSync} from "fs";
import * as pkg from "./package.json";
import { terser } from "rollup-plugin-terser";
import typescript from "@rollup/plugin-typescript";
// import { nodeResolve } from "@rollup/plugin-node-resolve";
// 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(", ");
const globals = Object.assign({}, ...Object.keys(pkg.dependencies || {}).filter(key => /^d3-/.test(key)).map(key => ({[key]: "d3"})))
const external = Object.keys(pkg.dependencies || {}).filter((key) =>/^(d3-)/.test(key));
// console.log({ globals ,external });
// standalone ES module
const config = {
input: "src/index.ts",
external,
output: {
file: `dist/${pkg.name}.js`,
format: "es",
banner: `// ${pkg.homepage} v${pkg.version} Copyright ${copyright}`,
name: "d3",
extend: true,
globals
},
plugins: [typescript()],
};
// d3 module: d3.ternaryPlot() and d3.barycentric()
const umdConfig = {
...config,
output: {
...config.output,
file: `dist/${pkg.name}.umd.js`,
format: "umd"
},
plugins: [typescript()],
};
const minifiedConfig = {
...config,
output: {
...config.output,
file: `dist/${pkg.name}.min.js`,
},
plugins: [
...config.plugins,
terser({
output: {
preamble: config.output.banner,
},
}),
],
};
const minifiedUmdConfig = {
...umdConfig,
output: {
...umdConfig.output,
file: `dist/${pkg.name}.umd.min.js`,
},
plugins: [
...umdConfig.plugins,
terser({
output: {
preamble: config.output.banner,
},
}),
],
};
export default [config, umdConfig, minifiedUmdConfig, minifiedConfig];