mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
allow disabling async importer
This commit is contained in:
parent
ad4fc18ab8
commit
ee27e3b5fe
@ -20,7 +20,6 @@ async function main () {
|
|||||||
buildDir: '',
|
buildDir: '',
|
||||||
targets: [],
|
targets: [],
|
||||||
nuxt: 2,
|
nuxt: 2,
|
||||||
dynamicImporter: undefined,
|
|
||||||
importSync: "require('../server/' + chunkId)",
|
importSync: "require('../server/' + chunkId)",
|
||||||
importAsync: "Promise.resolve(require('../server/' + chunkId))",
|
importAsync: "Promise.resolve(require('../server/' + chunkId))",
|
||||||
target: process.argv[3] && process.argv[3][0] !== '-' ? process.argv[3] : null,
|
target: process.argv[3] && process.argv[3][0] !== '-' ? process.argv[3] : null,
|
||||||
@ -51,10 +50,8 @@ async function main () {
|
|||||||
consola.info('Generated', prettyPath(htmlTemplateFileJS))
|
consola.info('Generated', prettyPath(htmlTemplateFileJS))
|
||||||
|
|
||||||
// Collect dynamic chunks
|
// Collect dynamic chunks
|
||||||
if (!config.dynamicImporter) {
|
consola.info('Collecting dynamic chunks...')
|
||||||
consola.info('Collecting dynamic chunks...')
|
const dynamicImporter = await createDynamicImporter(resolve(config.buildDir, 'dist/server'))
|
||||||
config.dynamicImporter = await createDynamicImporter(resolve(config.buildDir, 'dist/server'))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bundle for each target
|
// Bundle for each target
|
||||||
for (let target of config.targets) {
|
for (let target of config.targets) {
|
||||||
@ -72,7 +69,8 @@ async function main () {
|
|||||||
const ctx: any = defu(
|
const ctx: any = defu(
|
||||||
target,
|
target,
|
||||||
config,
|
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()
|
const hooks = new Hookable()
|
||||||
|
@ -70,7 +70,7 @@ export const getRollupConfig = (config) => {
|
|||||||
if (config.dynamicImporter) {
|
if (config.dynamicImporter) {
|
||||||
options.output.intro += config.dynamicImporter(config.importSync, config.importAsync)
|
options.output.intro += config.dynamicImporter(config.importSync, config.importAsync)
|
||||||
} else {
|
} else {
|
||||||
options.output.intro += 'const requireDynamic = require;'
|
options.output.intro += `const requireDynamic = (chunkId) => ${config.importSync}`
|
||||||
}
|
}
|
||||||
options.plugins.push(replace({ values: { 'require("./" +': 'requireDynamic(' }, delimiters: ['', ''] }))
|
options.plugins.push(replace({ values: { 'require("./" +': 'requireDynamic(' }, delimiters: ['', ''] }))
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import consola from 'consola'
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
entry: require.resolve('./entry'),
|
entry: require.resolve('./entry'),
|
||||||
|
dynamicImporter: false,
|
||||||
hooks: {
|
hooks: {
|
||||||
'rollup:done' (_ctx) {
|
'rollup:done' (_ctx) {
|
||||||
consola.info('Run `vercel deploy` to deploy!')
|
consola.info('Run `vercel deploy` to deploy!')
|
||||||
|
Loading…
Reference in New Issue
Block a user