mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Make dynamic import spec compliant. (#2612)
* Make dynamic import spec compliant. Now we simply return the whole module incl. default field In 'next/dynamic' we pick the default field if there is. Since modules with default is mostly used next/dynamic, for the enduser, this change has no effect. * Rename module into m Using module could be confusing.
This commit is contained in:
parent
89d4e0af4a
commit
2f7e459210
|
@ -54,7 +54,8 @@ export default function dynamicComponent (p, o) {
|
||||||
}
|
}
|
||||||
|
|
||||||
loadComponent () {
|
loadComponent () {
|
||||||
promise.then((AsyncComponent) => {
|
promise.then((m) => {
|
||||||
|
const AsyncComponent = m.default || m
|
||||||
// Set a readable displayName for the wrapper component
|
// Set a readable displayName for the wrapper component
|
||||||
const asyncCompName = getDisplayName(AsyncComponent)
|
const asyncCompName = getDisplayName(AsyncComponent)
|
||||||
if (asyncCompName) {
|
if (asyncCompName) {
|
||||||
|
@ -65,7 +66,7 @@ export default function dynamicComponent (p, o) {
|
||||||
this.setState({ AsyncComponent })
|
this.setState({ AsyncComponent })
|
||||||
} else {
|
} else {
|
||||||
if (this.isServer) {
|
if (this.isServer) {
|
||||||
registerChunk(AsyncComponent.__webpackChunkName)
|
registerChunk(m.__webpackChunkName)
|
||||||
}
|
}
|
||||||
this.state.AsyncComponent = AsyncComponent
|
this.state.AsyncComponent = AsyncComponent
|
||||||
}
|
}
|
||||||
|
@ -100,9 +101,10 @@ export default function dynamicComponent (p, o) {
|
||||||
|
|
||||||
const loadModule = (name) => {
|
const loadModule = (name) => {
|
||||||
const promise = modulePromiseMap[name]
|
const promise = modulePromiseMap[name]
|
||||||
promise.then((Component) => {
|
promise.then((m) => {
|
||||||
|
const Component = m.default || m
|
||||||
if (this.isServer) {
|
if (this.isServer) {
|
||||||
registerChunk(Component.__webpackChunkName)
|
registerChunk(m.__webpackChunkName)
|
||||||
}
|
}
|
||||||
moduleMap[name] = Component
|
moduleMap[name] = Component
|
||||||
remainingPromises--
|
remainingPromises--
|
||||||
|
|
|
@ -13,7 +13,6 @@ const buildImport = (args) => (template(`
|
||||||
eval('require.ensure = function (deps, callback) { callback(require) }')
|
eval('require.ensure = function (deps, callback) { callback(require) }')
|
||||||
require.ensure([], (require) => {
|
require.ensure([], (require) => {
|
||||||
let m = require(SOURCE)
|
let m = require(SOURCE)
|
||||||
m = m.default || m
|
|
||||||
m.__webpackChunkName = '${args.name}.js'
|
m.__webpackChunkName = '${args.name}.js'
|
||||||
resolve(m);
|
resolve(m);
|
||||||
}, 'chunks/${args.name}.js');
|
}, 'chunks/${args.name}.js');
|
||||||
|
@ -23,13 +22,12 @@ const buildImport = (args) => (template(`
|
||||||
const weakId = require.resolveWeak(SOURCE)
|
const weakId = require.resolveWeak(SOURCE)
|
||||||
try {
|
try {
|
||||||
const weakModule = __webpack_require__(weakId)
|
const weakModule = __webpack_require__(weakId)
|
||||||
return resolve(weakModule.default || weakModule)
|
return resolve(weakModule)
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
|
|
||||||
require.ensure([], (require) => {
|
require.ensure([], (require) => {
|
||||||
try {
|
try {
|
||||||
let m = require(SOURCE)
|
let m = require(SOURCE)
|
||||||
m = m.default || m
|
|
||||||
resolve(m)
|
resolve(m)
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
reject(error)
|
reject(error)
|
||||||
|
|
Loading…
Reference in a new issue