Skip to content

Commit

Permalink
fix: improve creating source maps
Browse files Browse the repository at this point in the history
  • Loading branch information
orlov-vo committed Nov 1, 2021
1 parent 9f3ff2a commit 498e967
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ function generateName(input) {
return name[0].toUpperCase() + name.slice(1);
}

function extractSourceMaps(asset, sourceMap) {
if (!sourceMap) return;
function extractSourceMaps(projectRoot, asset, originalSourceMap, sourceMap) {
if (!sourceMap) return originalSourceMap;

sourceMap.sources = [asset.filePath];

const map = new SourceMap();
const map = new SourceMap(projectRoot);
map.addVLQMap(sourceMap);

if (originalSourceMap) {
map.extends(originalSourceMap.toBuffer());
}

return map;
}

Expand Down Expand Up @@ -76,13 +80,23 @@ exports.default = new Transformer({
type: 'js',
content: js.code,
uniqueKey: `${asset.id}-js`,
map: extractSourceMaps(asset, js.map),
map: extractSourceMaps(
options.projectRoot,
asset,
originalSourceMap,
js.map,
),
},
Boolean(css && css.code) && {
type: 'css',
content: css.code,
uniqueKey: `${asset.id}-css`,
map: extractSourceMaps(asset, css.map),
map: extractSourceMaps(
options.projectRoot,
asset,
originalSourceMap,
css.map,
),
},
].filter(Boolean);
},
Expand Down

0 comments on commit 498e967

Please sign in to comment.