Last active
January 13, 2022 10:10
-
-
Save threepointone/d01eabcdc2485c234e9303b8424df556 to your computer and use it in GitHub Desktop.
fix for ssr + dynamic imports with webpack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ensure(moduleId, fn, done){ | |
if(__webpack_modules__[moduleId]) { //eslint-disable-line no-undef | |
return done(undefined, __webpack_require__(moduleId)) //eslint-disable-line no-undef | |
} | |
fn().then(Module => done(undefined, Module), done) | |
} | |
// usage | |
ensure(require.resolveWeak('./x.js'), | |
async () => import('./x.js'), | |
// or use require.ensure for predictable chunk names | |
// () => require.ensure([], require => require('./x.js'), chunk) | |
(err, Module) => { | |
// this could be possibly sync | |
// if you've loaded your chunks in the correct order | |
// so rehydrating with react will be fine | |
// ... do as you will! | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment