Skip to content

Commit

Permalink
fix: Fix source maps
Browse files Browse the repository at this point in the history
* Fix missing source map register if the v8 cache enabled
* Fix missing source maps if the v8 cache disabled
  • Loading branch information
yuriipalii committed Nov 22, 2021
1 parent 283e40b commit 0cceb53
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/index.js
Expand Up @@ -490,25 +490,25 @@ function ncc (
// custom terser phase used over Webpack integration for this reason
if (!result || result.code === undefined)
throw null;

({ code, map } = {
code: result.code,
map: map ? JSON.parse(result.map) : undefined
});
}
catch (e) {
console.log('An error occurred while minifying. The result will not be minified.');
console.log('An error occurred while minifying. The result will not be minified.');
}
}

if (map) {
assets[`${filename}.map`] = { source: JSON.stringify(map), permissions: defaultPermissions };
}

if (v8cache) {
const { Script } = require('vm');
assets[`${filename}.cache`] = { source: new Script(code).createCachedData(), permissions: defaultPermissions };
assets[`${filename}.cache${ext}`] = { source: code, permissions: defaultPermissions };
if (map) {
assets[filename + '.map'] = { source: JSON.stringify(map), permissions: defaultPermissions };
map = undefined;
}
const columnOffset = -'(function (exports, require, module, __filename, __dirname) { '.length;
code =
`const { readFileSync, writeFileSync } = require('fs'), { Script } = require('vm'), { wrap } = require('module');\n` +
Expand Down

0 comments on commit 0cceb53

Please sign in to comment.