Skip to content

Commit

Permalink
fix: performance (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Oct 28, 2020
1 parent 1330aef commit 78d821b
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,30 +223,6 @@ class TerserPlugin {
.map(async (name) => {
const { info, source } = compilation.getAsset(name);

let input;
let inputSourceMap;

const { source: sourceFromInputSource, map } = source.sourceAndMap();

input = sourceFromInputSource;

if (map) {
if (TerserPlugin.isSourceMap(map)) {
inputSourceMap = map;
} else {
inputSourceMap = map;

compilation.warnings.push(
/** @type {WebpackError} */
(new Error(`${name} contains invalid source map`))
);
}
}

if (Buffer.isBuffer(input)) {
input = input.toString();
}

const eTag = cache.getLazyHashedEtag(source);
const cacheItem = cache.getItemCache(name, eTag);
const output = await cacheItem.getPromise();
Expand All @@ -255,7 +231,7 @@ class TerserPlugin {
numberOfAssetsForMinify += 1;
}

return { name, info, input, inputSourceMap, output, cacheItem };
return { name, info, inputSource: source, output, cacheItem };
})
);

Expand Down Expand Up @@ -322,10 +298,37 @@ class TerserPlugin {
for (const asset of assetsForMinify) {
scheduledTasks.push(
limit(async () => {
const { name, input, inputSourceMap, info, cacheItem } = asset;
const { name, inputSource, info, cacheItem } = asset;
let { output } = asset;

if (!output) {
let input;
let inputSourceMap;

const {
source: sourceFromInputSource,
map,
} = inputSource.sourceAndMap();

input = sourceFromInputSource;

if (map) {
if (TerserPlugin.isSourceMap(map)) {
inputSourceMap = map;
} else {
inputSourceMap = map;

compilation.warnings.push(
/** @type {WebpackError} */
(new Error(`${name} contains invalid source map`))
);
}
}

if (Buffer.isBuffer(input)) {
input = input.toString();
}

const options = {
name,
input,
Expand Down

0 comments on commit 78d821b

Please sign in to comment.