import fs from 'node:fs' import path from 'node:path' // public 是无条件复制区:只发布驾驶舱资源,不发布演示、工具或本机配置。 const PUBLIC_ASSETS = ['cockpit/assets', 'cockpit/models', 'cockpit/aerial.webp', 'logo.png'] export default function cockpitStatic() { let config return { name: 'cockpit-static-allowlist', config() { return { build: { copyPublicDir: false } } }, configResolved(resolved) { config = resolved }, generateBundle() { // 旧目录即使被恢复,也不能悄悄回到驾驶舱产物。 for (const id of this.getModuleIds()) { const relative = path.relative(config.root, id).split(path.sep).join('/') if (/^(?:src\/plugins|tools|verify|[.]local-archive|dynamic-component-service-master)\//.test(relative)) { this.error('驾驶舱构建不允许引用隔离内容:' + id) } } }, writeBundle() { if (config.command !== 'build') return const outDir = path.resolve(config.root, config.build.outDir) for (const relative of PUBLIC_ASSETS) { const source = path.resolve(config.publicDir, relative) const target = path.resolve(outDir, relative) fs.mkdirSync(path.dirname(target), { recursive: true }) fs.cpSync(source, target, { recursive: true, filter: (file) => !file.endsWith('.md') }) } }, } }