Skip to content

Commit

Permalink
fix(builder): printFileSize throw err when set output.filename query (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fireairforce authored Nov 22, 2023
1 parent 7459705 commit 9016367
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/warm-cups-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/builder': patch
---

fix(builder): printFileSize throw err when set output.filename query
fix(builder): printFileSize 报错当用户设置了 filename query 参数
7 changes: 4 additions & 3 deletions packages/builder/builder/src/plugins/fileSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ async function printFileSizes(stats: Stats | MultiStats, distPath: string) {
);

const formatAsset = (asset: StatsAsset) => {
const contents = fs.readFileSync(path.join(distPath, asset.name));
const fileName = asset.name.split('?')[0];
const contents = fs.readFileSync(path.join(distPath, fileName));
const size = contents.length;
const gzippedSize = gzipSize.sync(contents);

return {
size,
folder: path.join(path.basename(distPath), path.dirname(asset.name)),
name: path.basename(asset.name),
folder: path.join(path.basename(distPath), path.dirname(fileName)),
name: path.basename(fileName),
gzippedSize,
sizeLabel: filesize(size, { round: 1 }),
gzipSizeLabel: getAssetColor(gzippedSize)(
Expand Down

0 comments on commit 9016367

Please sign in to comment.