Skip to content

Commit

Permalink
update wrapper approach
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jan 18, 2019
1 parent b7d075a commit 28da385
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,9 @@ module.exports = (
assets[filename + '.cache.js'] = code;
if (map)
assets[filename + '.map'] = map;
code = `const { readFileSync } = require('fs'), { Script } = require('vm');\n` +
code = `const { readFileSync } = require('fs'), { Script } = require('vm'), { wrap } = require('module');\n` +
`const source = readFileSync(__dirname + '/${filename}.cache.js').toString(), cachedData = readFileSync(__dirname + '/${filename}.cache');\n` +
`Object.assign(global, { module, exports, require, __filename, __dirname });\n` +
`new Script(source, { cachedData }).runInThisContext();\n`;
`(new Script(wrap(source), { cachedData }).runInThisContext())(exports, require, module, __filename, __dirname);\n`;
if (map) map = {};
}

Expand Down

0 comments on commit 28da385

Please sign in to comment.