diff --git a/.changeset/warm-cups-cross.md b/.changeset/warm-cups-cross.md new file mode 100644 index 000000000000..529025ff660c --- /dev/null +++ b/.changeset/warm-cups-cross.md @@ -0,0 +1,6 @@ +--- +'@modern-js/builder': patch +--- + +fix(builder): printFileSize throw err when set output.filename query +fix(builder): printFileSize 报错当用户设置了 filename query 参数 diff --git a/packages/builder/builder/src/plugins/fileSize.ts b/packages/builder/builder/src/plugins/fileSize.ts index 83df363702b9..94d72ec37290 100644 --- a/packages/builder/builder/src/plugins/fileSize.ts +++ b/packages/builder/builder/src/plugins/fileSize.ts @@ -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)(