mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
feat: add hint to dynamic require for netlify
This commit is contained in:
parent
536155825b
commit
f7378db9e0
@ -12,7 +12,7 @@ interface Import {
|
||||
import: string
|
||||
}
|
||||
|
||||
const TMPL_INLINE = ({ imports }: { imports: Import[]}) =>
|
||||
const TMPL_ESM_INLINE = ({ imports }: { imports: Import[]}) =>
|
||||
`${imports.map(i => `import ${i.name} from '${i.import.replace(/\\/g, '/')}'`).join('\n')}
|
||||
const dynamicChunks = {
|
||||
${imports.map(i => ` ['${i.id}']: ${i.name}`).join(',\n')}
|
||||
@ -22,10 +22,19 @@ export default function dynamicRequire(id) {
|
||||
return dynamicChunks[id];
|
||||
};`
|
||||
|
||||
const TMPL_CJS = ({ chunksDir }) => `export default function dynamicRequire(id) {
|
||||
return require('./${chunksDir}/' + id);
|
||||
const TMPL_CJS_LAZY = ({ imports, chunksDir }) =>
|
||||
`const dynamicChunks = {
|
||||
${imports.map(i => ` ['${i.id}']: () => require('./${chunksDir}/${i.id}')`).join(',\n')}
|
||||
};
|
||||
|
||||
export default function dynamicRequire(id) {
|
||||
return dynamicChunks[id];
|
||||
};`
|
||||
|
||||
// const TMPL_CJS = ({ chunksDir }) => `export default function dynamicRequire(id) {
|
||||
// return require('./${chunksDir}/' + id);
|
||||
// };`
|
||||
|
||||
interface Options {
|
||||
dir: string
|
||||
globbyOptions: GlobbyOptions
|
||||
@ -53,7 +62,7 @@ export default function dynamicRequire ({ dir, globbyOptions, outDir, chunksDir
|
||||
}))
|
||||
|
||||
if (!outDir) {
|
||||
return TMPL_INLINE({ imports })
|
||||
return TMPL_ESM_INLINE({ imports })
|
||||
}
|
||||
|
||||
// Write chunks
|
||||
@ -63,7 +72,7 @@ export default function dynamicRequire ({ dir, globbyOptions, outDir, chunksDir
|
||||
await mkdirp(dirname(dst))
|
||||
await copyFile(i.import, dst)
|
||||
}))
|
||||
return TMPL_CJS({ chunksDir })
|
||||
return TMPL_CJS_LAZY({ chunksDir, imports })
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user