perf: dynamic import demo file

This commit is contained in:
chenjiahan 2021-09-05 15:55:08 +08:00
parent 5ecf7460cf
commit b4be171028

View File

@ -17,17 +17,17 @@ type DemoItem = {
};
function genInstall() {
return `import packageEntry from './package-entry';
return `import { defineAsyncComponent } from 'vue';
import './package-style.less';
`;
}
function genImports(demos: DemoItem[]) {
return demos
.map(
(item) =>
`import ${item.name} from '${removeExt(normalizePath(item.path))}';`
)
.map((item) => {
const path = removeExt(normalizePath(item.path));
return `const ${item.name} = defineAsyncComponent(() => import('${path}'))`;
})
.join('\n');
}
@ -82,8 +82,6 @@ function genCode(components: string[]) {
return `${genInstall()}
${genImports(demos)}
export { packageEntry };
${getSetName(demos)}
${genExports(demos)}