-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.mjs
106 lines (97 loc) · 2.6 KB
/
rollup.config.mjs
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
import nodeResolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import typescript from "rollup-plugin-typescript2";
import clear from "rollup-plugin-clear";
import dts from "rollup-plugin-dts";
import json from "@rollup/plugin-json";
import path from "path";
import * as url from "url";
import fs from "fs-extra"
import externals from "rollup-plugin-node-externals"
import {visualizer} from "rollup-plugin-visualizer";
import keepHeaderComment from "rollup-plugin-keep-header-comment";
const __filename = url.fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
console.log(__dirname);
const resolve = p => path.resolve(__dirname, p);
const packageJson = fs.readJSONSync(resolve("package.json"))
const tsconfig = resolve("tsconfig.json")
const tsconfigJson = fs.readJSONSync(tsconfig)
const input = "./src/index.ts"
const {
outDir: outputDir,
sourceMap: sourcemap
} = tsconfigJson["compilerOptions"]
const {
name: pkgName,
types: declarationFile
} = packageJson
let name = path.basename(pkgName).replaceAll("-", "_")
const Format = {
ES: "es",
CJS: "cjs",
IIFE: "iife",
}
const emitFormats = [
Format.ES,
Format.CJS,
Format.IIFE
]
const outputFileMapper = {
[Format.ES]: "index.mjs",
[Format.CJS]: "index.cjs",
[Format.IIFE]: "index.iife.js"
}
const basePlugins = [
clear({
targets: ["dist"],
}),
json(),
nodeResolve({
preferBuiltins: false,
}),
commonjs(),
typescript({
tsconfig,
}),
externals()
];
export default [
...emitFormats.map(format =>{
return {
input,
output: {
file: resolve(path.join(outputDir, outputFileMapper[format])),
format,
name,
exports: "named",
sourcemap,
},
plugins:[
...basePlugins,
...["sunburst", "treemap", "network", "raw-data"].map(template => visualizer({
filename: resolve(path.join("stat", `${format}.stat.${template}${template === "raw-data" ? "raw" : ".html"}`)),
template
})),
]
}
}),
{
input,
output: [{
file: resolve(declarationFile),
format: "es"
}],
plugins: [
...basePlugins,
dts({
tsconfig,
}),
keepHeaderComment({
sourcemap,
pattern: /@packageDocumentation/,
}),
],
external: ["type-fest"]
}
];