rt-graphic-component/rollup.config.cjs
2024-01-04 10:44:03 +08:00

44 lines
1.1 KiB
JavaScript

const { resolve, relative, extname } = require('path');
const { readdirSync } = require('fs');
const typescript = require('@rollup/plugin-typescript');
/**
* @type {import('rollup').RollupOptions}
*/
const config = {
external: ['jl-graphic'],
input: getEntryPoints('src/packages', 'src'),
output: {
dir: 'components',
format: 'esm',
preserveModules: true,
},
plugins: [
typescript({
tsconfig: './tsconfig.json',
compilerOptions: {
declaration: true,
declarationDir: 'components',
},
}),
],
};
module.exports = config;
function getEntryPoints(dir, root) {
let entries = {};
const items = readdirSync(dir, { withFileTypes: true });
for (const item of items) {
const fullPath = resolve(dir, item.name);
const relativePath = relative(root, fullPath);
const relativeName = relativePath.replace(extname(item.name), '');
if (item.isDirectory()) {
const subentries = getEntryPoints(fullPath, root);
entries = { ...entries, ...subentries };
} else {
entries[relativeName] = fullPath;
}
}
return entries;
}