Skip to content

Commit d5d0b76

Browse files
author
Guillaume Chau
committed
fix(ui): analyze bundle error handling
1 parent 0ac38da commit d5d0b76

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/@vue/cli-service/lib/webpack/analyzeBundle.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ const walk = require('acorn/dist/walk')
66
const mapValues = require('lodash.mapvalues')
77
const transform = require('lodash.transform')
88
const zlib = require('zlib')
9+
const { warn } = require('@vue/cli-shared-utils')
910

1011
exports.analyzeBundle = function analyzeBundle (bundleStats, assetSources) {
1112
// Picking only `*.js` assets from bundle that has non-empty `chunks` array
1213
const jsAssets = []
1314
const otherAssets = []
1415

16+
// Separate JS assets
1517
bundleStats.assets.forEach(asset => {
1618
if (asset.name.endsWith('.js') && asset.chunks && asset.chunks.length) {
1719
jsAssets.push(asset)
@@ -20,25 +22,25 @@ exports.analyzeBundle = function analyzeBundle (bundleStats, assetSources) {
2022
}
2123
})
2224

23-
// Trying to parse bundle assets and get real module sizes if `bundleDir` is provided
25+
// Trying to parse bundle assets and get real module sizes
2426
let bundlesSources = null
2527
let parsedModules = null
2628

2729
bundlesSources = {}
2830
parsedModules = {}
2931

3032
for (const asset of jsAssets) {
31-
const content = assetSources.get(asset.name)
33+
const source = assetSources.get(asset.name)
3234
let bundleInfo
3335

3436
try {
35-
bundleInfo = parseBundle(content)
37+
bundleInfo = parseBundle(source)
3638
} catch (err) {
3739
bundleInfo = null
3840
}
3941

4042
if (!bundleInfo) {
41-
console.warn(
43+
warn(
4244
`\nCouldn't parse bundle asset "${asset.fullPath}".\n` +
4345
'Analyzer will use module sizes from stats file.\n'
4446
)
@@ -51,8 +53,10 @@ exports.analyzeBundle = function analyzeBundle (bundleStats, assetSources) {
5153
Object.assign(parsedModules, bundleInfo.modules)
5254
}
5355

56+
// Update sizes
57+
5458
bundleStats.modules.forEach(module => {
55-
const parsedSrc = parsedModules[module.id]
59+
const parsedSrc = parsedModules && parsedModules[module.id]
5660
module.size = {
5761
stats: module.size
5862
}
@@ -66,7 +70,7 @@ exports.analyzeBundle = function analyzeBundle (bundleStats, assetSources) {
6670
})
6771

6872
jsAssets.forEach(asset => {
69-
const src = bundlesSources[asset.name]
73+
const src = bundlesSources && bundlesSources[asset.name]
7074
asset.size = {
7175
stats: asset.size
7276
}

0 commit comments

Comments
 (0)