rt-graphic-component/rollup.config.cjs

50 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2024-01-02 14:36:10 +08:00
const { resolve, relative, extname } = require('path');
const { readdirSync } = require('fs');
const typescript = require('@rollup/plugin-typescript');
2024-01-04 15:14:25 +08:00
const { default: alias } = require('@rollup/plugin-alias');
2023-12-19 14:20:48 +08:00
/**
* @type {import('rollup').RollupOptions}
*/
const config = {
2024-01-02 14:36:10 +08:00
external: ['jl-graphic'],
2024-01-04 10:42:05 +08:00
input: getEntryPoints('src/packages', 'src'),
2023-12-19 14:20:48 +08:00
output: {
2024-01-02 14:36:10 +08:00
dir: 'components',
format: 'esm',
2023-12-19 14:20:48 +08:00
preserveModules: true,
},
plugins: [
2024-01-04 15:14:25 +08:00
alias({
2024-01-09 15:03:25 +08:00
//FIXME components中生成的导入路径不可用待调整
//可能这个插件不太合适
2024-01-04 15:14:25 +08:00
entries: [{ find: 'common', replacement: 'src/common' }],
}),
2023-12-19 14:20:48 +08:00
typescript({
2024-01-02 14:36:10 +08:00
tsconfig: './tsconfig.json',
2023-12-19 14:20:48 +08:00
compilerOptions: {
declaration: true,
2024-01-02 14:36:10 +08:00
declarationDir: 'components',
2023-12-19 14:20:48 +08:00
},
}),
],
};
module.exports = config;
2024-01-02 14:36:10 +08:00
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;
2023-12-19 14:20:48 +08:00
}