mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
dynamic imports fix for non-webpack environments. (#3414)
* Added condition to check whether method exists or not * Conditional loop based on feature detection * Added code comments as requested by the author
This commit is contained in:
parent
5ce05c2d22
commit
bd20deb9ba
|
@ -7,9 +7,16 @@ import Crypto from 'crypto'
|
|||
|
||||
const TYPE_IMPORT = 'Import'
|
||||
|
||||
/*
|
||||
Added "typeof require.resolveWeak !== 'function'" check instead of
|
||||
"typeof window === 'undefined'" to support dynamic impports in non-webpack environments.
|
||||
"require.resolveWeak" and "require.ensure" are webpack specific methods.
|
||||
They would fail in Node/CommonJS environments.
|
||||
*/
|
||||
|
||||
const buildImport = (args) => (template(`
|
||||
(
|
||||
typeof window === 'undefined' ?
|
||||
typeof require.resolveWeak !== 'function' ?
|
||||
new (require('next/dynamic').SameLoopPromise)((resolve, reject) => {
|
||||
eval('require.ensure = function (deps, callback) { callback(require) }')
|
||||
require.ensure([], (require) => {
|
||||
|
|
Loading…
Reference in a new issue