-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
72 lines (68 loc) · 2 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
import svelte from "rollup-plugin-svelte";
import vue from "rollup-plugin-vue";
import css from "rollup-plugin-css-only";
import resolve from "rollup-plugin-node-resolve";
import { terser } from "rollup-plugin-terser";
import analyzer from "rollup-plugin-analyzer";
import progress from "rollup-plugin-progress";
import commonjs from "rollup-plugin-commonjs";
import json from "@rollup/plugin-json";
import builtins from "rollup-plugin-node-builtins";
import globals from "rollup-plugin-node-globals";
import clear from 'rollup-plugin-clear';
import pkg from "./package.json";
/**
* 因为ts的很多插件对svelte、vue框架兼容报错,只有rollup-plugin-typescript兼容。
* 但是只有rollup-plugin-typescript2会生成对应的type文件。
* 所以对于不同的npm包,采用不同的ts来打包,当开发纯js逻辑的包时,生成type文件,点当开发框架的包时,只兼容打包,不生成type文件。
*/
let ts;
if (pkg.useFrame === true) {
ts = require("rollup-plugin-typescript")();
} else {
ts = require("rollup-plugin-typescript2")({
verbosity: 2,
clean: true,
});
}
const name = pkg.name
.replace(/^(@\S+\/)?(svelte-)?(\S+)/, "$3")
.replace(/^\w/, m => m.toUpperCase())
.replace(/-\w/g, m => m[1].toUpperCase());
export default {
input: "src/index.ts",
output: [
{ file: `${pkg.module}`, format: "es" },
{ file: `${pkg.main}`, format: "umd", name: "ApiModule" }
],
plugins: [
clear({
targets: ['dist']
}),
globals(),
builtins(),
json(),
resolve(),
commonjs(),
ts,
svelte({
emitCss: true
}),
css(),
vue({
exclude: ["node_modules"],
css: false
}),
terser({
format: {
comments: "some",
},
}),
progress(),
analyzer({
// hideDeps: true,
filter: []
})
],
external: ["vue"]
};