-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
119 lines (110 loc) · 2.68 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import vue from "@vitejs/plugin-vue";
import { getBabelOutputPlugin } from "@rollup/plugin-babel";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import { terser } from "rollup-plugin-terser";
import alias from "@rollup/plugin-alias";
import jsImpoerSass from "./rollup-plugin-js-import-sass.js";
import clear from "rollup-plugin-clear";
import { DEFAULT_EXTENSIONS } from "@babel/core";
import typescript from "rollup-plugin-typescript2";
import components from "./component-list.js";
const isProd = process.env.NODE_ENV === "production";
const external = [
"element-plus",
/element-plus\/.+/,
"vue",
"rxjs",
"@element-plus/icons-vue"
];
const typePlugin = typescript({
check: false,
useTsconfigDeclarationDir: true
});
const componentsConfig = components.map((name) => {
return {
input: `src/${name}/index.ts`,
output: {
name,
file: `lib/${name}/index.js`,
format: "es"
},
plugins: [
nodeResolve(),
alias({
entries: [
{ find: "@", replacement: "src" },
{ find: /@core\/(.+)/, replacement: "@sugaz/gz-com/lib/$1" }
]
}),
vue(),
jsImpoerSass(),
typePlugin,
getBabelOutputPlugin({
presets: ["@babel/preset-env"],
plugins: [["@babel/plugin-transform-runtime"]]
})
],
external: [...external, /@sugaz\/gz-com\/.+/]
};
});
const indexConfig = {
input: "src/index.ts",
output: {
name: "index",
file: `lib/index.js`,
format: "es"
},
plugins: [
nodeResolve(),
vue({ isProduction: isProd }),
alias({
entries: [
{ find: "@", replacement: "src" },
{ find: /@core\/(.+)/, replacement: "core/$1" }
]
}),
typePlugin,
jsImpoerSass()
// getBabelOutputPlugin({
// presets: ["@babel/env", { modules: "umd" }]
// })
],
external
};
const utilsConfig = {
input: {
"utils/index": "core/utils/index.ts",
"hooks/index": "core/hooks/index.ts",
"config-provider": "core/config-provider.ts"
},
output: {
// name: "index",
// file: `lib/utils/index.js`,
dir: "lib",
entryFileNames: "[name].js",
format: "es"
},
plugins: [
clear({
targets: ["lib"]
}),
nodeResolve(),
typePlugin,
getBabelOutputPlugin({
extensions: [...DEFAULT_EXTENSIONS, ".ts", ".tsx"],
presets: ["@babel/preset-env"],
plugins: [["@babel/plugin-transform-runtime"]]
})
],
external
};
function getList() {
let list = [utilsConfig, indexConfig];
if (isProd) list = list.concat(componentsConfig);
return list;
}
const configs = getList().map((item) => {
if (isProd) item.plugins.push(terser());
return item;
});
export default configs;