Skip to content

Commit

Permalink
perf: only call sourceAndMap() when source maps are enabled (#316)
Browse files Browse the repository at this point in the history
Co-authored-by: Chevelle Boyer <chevelle.boyer@slack-corp.com>
  • Loading branch information
Chevelleboyer and cboyere36 committed Feb 14, 2023
1 parent c0cd46e commit 5c97454
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/plugin.ts
Expand Up @@ -56,18 +56,20 @@ const transformAssets = async (
const assetIsCss = isCssFile.test(asset.name);
let source: string | Buffer | ArrayBuffer;
let map = null;

if (asset.source.sourceAndMap) {
const sourceAndMap = asset.source.sourceAndMap();
source = sourceAndMap.source;
map = sourceAndMap.map;
if (useSourceMap) {
if (asset.source.sourceAndMap) {
const sourceAndMap = asset.source.sourceAndMap();
source = sourceAndMap.source;
map = sourceAndMap.map;
} else {
source = asset.source.source();
if (asset.source.map) {
map = asset.source.map();
}
}
} else {
source = asset.source.source();
if (asset.source.map) {
map = asset.source.map();
}
}

const sourceAsString = source.toString();
const result = await transform(sourceAsString, {
...transformOptions,
Expand Down

0 comments on commit 5c97454

Please sign in to comment.