allow disabling async importer

This commit is contained in:
Pooya Parsa 2020-11-02 15:54:18 +01:00
parent ad4fc18ab8
commit ee27e3b5fe
3 changed files with 6 additions and 7 deletions

View File

@ -20,7 +20,6 @@ async function main () {
buildDir: '',
targets: [],
nuxt: 2,
dynamicImporter: undefined,
importSync: "require('../server/' + chunkId)",
importAsync: "Promise.resolve(require('../server/' + chunkId))",
target: process.argv[3] && process.argv[3][0] !== '-' ? process.argv[3] : null,
@ -51,10 +50,8 @@ async function main () {
consola.info('Generated', prettyPath(htmlTemplateFileJS))
// Collect dynamic chunks
if (!config.dynamicImporter) {
consola.info('Collecting dynamic chunks...')
config.dynamicImporter = await createDynamicImporter(resolve(config.buildDir, 'dist/server'))
}
consola.info('Collecting dynamic chunks...')
const dynamicImporter = await createDynamicImporter(resolve(config.buildDir, 'dist/server'))
// Bundle for each target
for (let target of config.targets) {
@ -72,7 +69,8 @@ async function main () {
const ctx: any = defu(
target,
config,
tryImport(__dirname, `./targets/${target.target}`) || tryImport(config.rootDir, target.target)
tryImport(__dirname, `./targets/${target.target}`) || tryImport(config.rootDir, target.target),
{ dynamicImporter }
)
const hooks = new Hookable()

View File

@ -70,7 +70,7 @@ export const getRollupConfig = (config) => {
if (config.dynamicImporter) {
options.output.intro += config.dynamicImporter(config.importSync, config.importAsync)
} else {
options.output.intro += 'const requireDynamic = require;'
options.output.intro += `const requireDynamic = (chunkId) => ${config.importSync}`
}
options.plugins.push(replace({ values: { 'require("./" +': 'requireDynamic(' }, delimiters: ['', ''] }))

View File

@ -2,6 +2,7 @@ import consola from 'consola'
export default {
entry: require.resolve('./entry'),
dynamicImporter: false,
hooks: {
'rollup:done' (_ctx) {
consola.info('Run `vercel deploy` to deploy!')