-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.js
126 lines (118 loc) · 2.91 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
120
121
122
123
124
125
126
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import babel from "@rollup/plugin-babel";
import typescript from "@rollup/plugin-typescript";
import path from "path";
import { globSync } from "glob";
import { fileURLToPath } from "node:url";
const external = [
"react",
"react-dom",
"@univerjs/core",
"@univerjs/ui",
"@univerjs/sheets-drawing-ui",
"@visactor/react-vchart",
"@wendellhu/redi",
];
const inputs = Object.fromEntries(
globSync("src/**/*.ts").map((file) => [
// 这里将删除 `src/` 以及每个文件的扩展名。
// 因此,例如 src/nested/foo.js 会变成 nested/foo
path.relative(
"src",
file.slice(0, file.length - path.extname(file).length)
),
// 这里可以将相对路径扩展为绝对路径,例如
// src/nested/foo 会变成 /project/src/nested/foo.js
fileURLToPath(new URL(file, import.meta.url)),
])
);
export default [
// esm
{
input: inputs,
external: external,
output: {
dir: "esm",
format: "es",
sourcemap: true,
},
plugins: [
resolve({
browser: true,
modulesOnly: true,
customResolveOptions: { preserveSymlinks: false },
}), // so Rollup can find `ms`
commonjs(), // so Rollup can convert `ms` to an ES module
babel({
presets: [
[
"@babel/preset-env",
{
targets: "defaults and not IE 11",
},
],
[
"@babel/preset-typescript",
{
allowDeclareFields: true,
},
],
],
babelHelpers: "bundled",
extensions: [".js", ".ts"],
}),
typescript({
tsconfig: path.resolve(__dirname, "./tsconfig.json"),
target: "es6",
downlevelIteration: false,
declaration: true,
declarationDir: "esm",
}),
],
},
//cjs
{
input: inputs,
external: external,
output: {
dir: "cjs",
format: "cjs",
exports: "auto",
sourcemap: false,
},
plugins: [
resolve({
browser: false,
modulesOnly: true,
customResolveOptions: { preserveSymlinks: false },
}), // so Rollup can find `ms`
commonjs(), // so Rollup can convert `ms` to an ES module
babel({
presets: [
[
"@babel/preset-env",
{
targets: "defaults and not IE 11",
},
],
[
"@babel/preset-typescript",
{
allowDeclareFields: true,
},
],
],
babelHelpers: "bundled",
extensions: [".js", ".ts"],
}),
typescript({
tsconfig: path.resolve(__dirname, "./tsconfig.json"),
target: "es5",
downlevelIteration: true,
declaration: true,
declarationDir: "cjs",
}),
],
},
];