Skip to content

Commit

Permalink
Allow requiring Node builtins.
Browse files Browse the repository at this point in the history
This should fix #16, allowing Node builtin modules to be required when using a JS entry module.
  • Loading branch information
developit authored Feb 22, 2019
1 parent 5d827f8 commit 20ce748
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ async function prerender (parentCompilation, request, options, inject, loader) {
window.require = moduleId => {
const asset = compilation.assets[moduleId.replace(/^\.?\//g, '')];
if (!asset) {
throw Error(`Error: Module not found. attempted require("${moduleId}")`);
try {
return require(moduleId);
} catch (e) {
throw Error(`Error: Module not found. attempted require("${moduleId}")`);
}
}
const mod = { exports: {} };
window.eval(`(function(exports, module, require){\n${asset.source()}\n})`)(mod.exports, mod, window.require);
Expand Down

0 comments on commit 20ce748

Please sign in to comment.