-
Notifications
You must be signed in to change notification settings - Fork 743
/
Copy pathrollup.dts.config.js
61 lines (53 loc) · 2.03 KB
/
rollup.dts.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
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import alias from '@rollup/plugin-alias';
import dts from 'rollup-plugin-dts';
if (!existsSync('temp')) {
console.warn(
'no temp dts files found. run `tsc -p tsconfig.build-browser.json && vue-tsc --declaration --emitDeclarationOnly --project tsconfig.build-vue.json` first.',
);
process.exit(1);
}
removeScss('temp/packages/editor/src/index.d.ts');
removeScss('temp/packages/form/src/index.d.ts');
removeScss('temp/packages/design/src/index.d.ts');
removeScss('temp/packages/table/src/index.d.ts');
const packages = readdirSync('temp/packages');
const runtimes = readdirSync('temp/runtime');
const targets = process.env.TARGETS ? process.env.TARGETS.split(',') : null;
const targetPackages = targets ? packages.filter((pkg) => targets.includes(pkg)) : packages;
const __dirname = path.dirname(fileURLToPath(import.meta.url));
function rollupConfig(pkg, base) {
return {
input: `./temp/${base}/${pkg}/src/index.d.ts`,
output: {
file: `${base}/${pkg}/types/index.d.ts`,
format: 'es',
},
plugins: [
alias({
entries: [
{ find: /^@form/, replacement: path.join(__dirname, `./temp/packages/form/src`) },
{ find: /^@editor/, replacement: path.join(__dirname, `./temp/packages/editor/src`) },
{ find: /^@data-source/, replacement: path.join(__dirname, `./temp/packages/data-source/src`) },
],
}),
dts(),
],
onwarn(warning, warn) {
// during dts rollup, everything is externalized by default
if (warning.code === 'UNRESOLVED_IMPORT' && !warning.exporter?.startsWith('.')) {
return;
}
warn(warning);
},
};
}
export default [
...targetPackages.map((pkg) => rollupConfig(pkg, 'packages')),
...runtimes.map((pkg) => rollupConfig(pkg, 'runtime')),
];
function removeScss(path) {
writeFileSync(path, readFileSync(path).toString().replace(`import './theme/index.scss';`, ''));
}