-
Notifications
You must be signed in to change notification settings - Fork 715
/
rollup.dts.config.js
52 lines (46 loc) · 1.72 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
import alias from '@rollup/plugin-alias';
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
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/editor/src/index.d.ts');
removeScss('temp/form/src/index.d.ts');
removeScss('temp/design/src/index.d.ts');
removeScss('temp/table/src/index.d.ts');
const packages = readdirSync('temp');
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));
export default targetPackages.map((pkg) => ({
input: `./temp/${pkg}/src/index.d.ts`,
output: {
file: `packages/${pkg}/types/index.d.ts`,
format: 'es',
},
plugins: [
alias({
entries: [
{ find: /^@form/, replacement: path.join(__dirname, `./temp/form/src`) },
{ find: /^@editor/, replacement: path.join(__dirname, `./temp/editor/src`) },
{ find: /^@data-source/, replacement: path.join(__dirname, `./temp/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);
},
}));
function removeScss(path) {
writeFileSync(path, readFileSync(path).toString().replace(`import './theme/index.scss';`, ''));
}