Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow components to provide absolute import path #234

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would need to normalize windows paths in fullPath condition

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