Skip to content
Open
Changes from all commits
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
15 changes: 5 additions & 10 deletions src/route-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@ const loaderUtils = require('loader-utils');
function asyncRequire(page, chunk, shouldChunk) {
// load in main chunk if explicitly specified, or if chunks option was set to false
if ((chunk && chunk === 'main') || (!chunk && shouldChunk === false)) {
return `Promise.resolve(require('${page}').default)`;
return `import('${page}').then(m => m.default)`;
}
// load in separate chunk if chunk name was not specified, or if is not named "main"
return `new Promise(function (resolve, reject) {
try {
require.ensure(['${page}'], function (require) {
resolve(require('${page}').default);
}${typeof chunk === 'string' ? `, '${chunk}'` : ''});
} catch (err) {
reject(err);
}
})`;
return `import(${typeof chunk === 'string' ? `
/* webpackChunkName: "${chunk}" */` : ''}
'${page}'
).then(m => m.default)`;
}

/**
Expand Down