-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.scripts.js
91 lines (85 loc) · 1.95 KB
/
rollup.scripts.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
import babel from "rollup-plugin-babel";
import { terser } from "rollup-plugin-terser";
import esbuild from "rollup-plugin-esbuild";
import dts from "rollup-plugin-dts";
import resolve from "rollup-plugin-node-resolve";
const createBuild = (options) => {
const { format, id, name, minify = false, transpile = false } = options;
// get filename
const filename = ["lib/", name];
if (format === "es") {
filename.push(".esm");
}
if (format === "umd") {
// filename.push(".umd");
}
if (minify) {
filename.push(".min");
}
filename.push(".js");
// collect plugins
const plugins = [
resolve({
preferBuiltins: true,
browser: true,
}),
];
if (transpile) {
plugins.push(
babel({
exclude: ["node_modules/**"],
})
);
}
if (minify) {
plugins.push(terser());
} else {
// plugins.push(
// prettier({
// singleQuote: true,
// parser: "babel",
// })
// );
}
// plugins.push(license({ banner: banner(options) }));
plugins.push(esbuild());
// return Rollup config
return {
input: "src/index.ts",
treeshake: true,
output: {
format,
name: id,
file: filename.join(""),
globals: {
axios: "axios",
},
},
plugins,
external: [
"axios",
"http", // imported by axios
"https", // imported by axios
"url", // imported by follow-redirects
"assert", // imported by follow-redirects
"stream", // imported by follow-redirects
"tty", // imported by follow-redirects
"util", // imported by follow-redirects
"zlib", // imported by axios
],
};
};
export default (metadata, configs) => [
// ...configs.map((config) => createBuild({ ...metadata, ...config })),
{
plugins: [dts()],
input: "src/index.ts",
output: {
file: `./lib/index.d.ts`,
format: "es",
},
external: (id) => {
return !/^[./]/.test(id);
},
},
];