From 2e60935de3c7e64cd9b07070afa1580d052c8aec Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Thu, 16 Sep 2021 03:43:36 +0800 Subject: [PATCH] feat: allow components to provide absolute import path --- src/types.ts | 1 + templates/components/index.js | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/types.ts b/src/types.ts index bf2197a..b8dc6b6 100644 --- a/src/types.ts +++ b/src/types.ts @@ -7,6 +7,7 @@ export interface Component { filePath: string shortPath: string isAsync?: boolean + isAbsolute?: boolean chunkName: string /** @deprecated */ global: boolean diff --git a/templates/components/index.js b/templates/components/index.js index fe252b2..e19b49d 100644 --- a/templates/components/index.js +++ b/templates/components/index.js @@ -4,13 +4,14 @@ c.prefetch === true || typeof c.prefetch === 'number' ? `webpackPrefetch: ${c.prefetch}` : false, c.preload === true || typeof c.preload === 'number' ? `webpackPreload: ${c.preload}` : false, ].filter(Boolean).join(', ') + const filePath = c.isAbsolute ? c.filePath : `../${relativeToBuild(c.filePath)}` if (c.isAsync === true || (!isDev /* prod fallback */ && c.isAsync === null)) { const exp = c.export === 'default' ? `c.default || c` : `c['${c.export}']` - const asyncImport = `() => import('../${relativeToBuild(c.filePath)}' /* ${magicComments} */).then(c => wrapFunctional(${exp}))` + const asyncImport = `() => import('${filePath}' /* ${magicComments} */).then(c => wrapFunctional(${exp}))` return `export const ${c.pascalName} = ${asyncImport}` } else { const exp = c.export === 'default' ? `default as ${c.pascalName}` : c.pascalName - return `export { ${exp} } from '../${relativeToBuild(c.filePath)}'` + return `export { ${exp} } from '${filePath}'` } }).join('\n') %>