rt-graphic-component/rollup.config.cjs

50 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { resolve, relative, extname } = require('path');
const { readdirSync } = require('fs');
const typescript = require('@rollup/plugin-typescript');
const { default: alias } = require('@rollup/plugin-alias');
/**
* @type {import('rollup').RollupOptions}
*/
const config = {
external: ['jl-graphic'],
input: getEntryPoints('src/packages', 'src'),
output: {
dir: 'components',
format: 'esm',
preserveModules: true,
},
plugins: [
alias({
//FIXME components中生成的导入路径不可用待调整
//可能这个插件不太合适
entries: [{ find: 'common', replacement: 'src/common' }],
}),
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;
}