Skip to content

Commit

Permalink
Merge pull request #30 from GoogleChromeLabs/allow-node-builtins
Browse files Browse the repository at this point in the history
Allow requiring Node builtins.
  • Loading branch information
developit authored Feb 22, 2019
2 parents c9186fe + 9725b28 commit ec2320f
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 ec2320f

Please sign in to comment.