-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
rollup.config.js
90 lines (84 loc) · 2.17 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import replace from "@rollup/plugin-replace";
import esbuild from "rollup-plugin-esbuild";
import { dts } from "rollup-plugin-dts";
import css from "rollup-plugin-import-css";
import { injectVueDemi } from "./scripts/rollup.mjs";
/**
* Modifies the Rollup options for a build to support strict CSP
* @param {import('rollup').RollupOptions} options the original options
* @param {boolean} csp whether to support strict CSP
* @returns {import('rollup').RollupOptions} the modified options
*/
function configBuild(options, csp) {
const result = { ...options };
const { plugins, output } = result;
result.plugins = [
...(csp ? [replace({ __CSP__: `${csp}`, preventAssignment: true })] : []),
...plugins,
csp ? css({ output: "style.css" }) : css({ inject: true })
];
// modify output file names
if (csp && output) {
result.output = (Array.isArray(output) ? output : [output]).map(output => {
return {
...output,
file: output.file.replace(/^dist\//, "dist/csp/"),
assetFileNames: "[name][extname]"
};
});
}
return result;
}
/** @type {import('rollup').RollupOptions[]} */
const builds = [
{
input: "src/index.ts",
plugins: [esbuild()],
external: ["vue-demi", /^echarts/],
output: [
{
file: "dist/index.js",
format: "esm",
sourcemap: true
}
]
},
{
input: "src/global.ts",
plugins: [esbuild({ minify: true })],
external: ["vue-demi", /^echarts/],
output: [
{
file: "dist/index.min.js", // for unpkg/jsdelivr
format: "umd",
name: "VueECharts",
exports: "default",
sourcemap: true,
globals: {
"vue-demi": "VueDemi",
echarts: "echarts",
"echarts/core": "echarts"
},
plugins: [injectVueDemi]
}
]
}
];
export default [
...builds.map(options => configBuild(options, false)),
...builds.map(options => configBuild(options, true)),
{
input: "src/index.d.ts",
plugins: [dts()],
output: [
{
file: "dist/index.d.ts",
format: "esm"
},
{
file: "dist/csp/index.d.ts",
format: "esm"
}
]
}
];