Skip to content

Commit

Permalink
feat: allow components to provide absolute import path
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 15, 2021
1 parent f8667b6 commit 2e60935
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface Component {
filePath: string
shortPath: string
isAsync?: boolean
isAbsolute?: boolean
chunkName: string
/** @deprecated */
global: boolean
Expand Down
5 changes: 3 additions & 2 deletions templates/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') %>

Expand Down

0 comments on commit 2e60935

Please sign in to comment.