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; }