Skip to content

Commit

Permalink
fix: ignore css chunk (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
jas0ncn committed Jan 24, 2021
1 parent c8eb7f7 commit 6926e19
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
23 changes: 22 additions & 1 deletion packages/server/src/ChunkExtractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ function isValidChunkAsset(chunkAsset) {
return chunkAsset.scriptType && !HOT_UPDATE_REGEXP.test(chunkAsset.filename)
}

const JS_FILE = /\.js$/
function checkIfChunkIncludesJs(chunkInfo) {
return chunkInfo.files.some(file => JS_FILE.test(file.split('?')[0]))
}

class ChunkExtractor {
constructor({
statsFile,
Expand Down Expand Up @@ -201,6 +206,12 @@ class ChunkExtractor {
return chunkGroup
}

getChunkInfo(chunkId) {
const chunkInfo = this.stats.chunks.find(chunk => chunk.id === chunkId)
invariant(chunkInfo, `cannot find chunk (chunkId: ${chunkId}) in stats`)
return chunkInfo
}

createChunkAsset({ filename, chunk, type, linkType }) {
const resolvedFilename =
typeof filename === 'object' && filename.name ? filename.name : filename
Expand Down Expand Up @@ -269,7 +280,17 @@ class ChunkExtractor {
getChunkDependencies(chunks) {
const one = chunk => {
const chunkGroup = this.getChunkGroup(chunk)
return chunkGroup.chunks

// ignore chunk that only contains css files.
return chunkGroup.chunks.filter(chunkId => {
const chunkInfo = this.getChunkInfo(chunkId)

if (!chunkInfo) {
return false
}

return checkIfChunkIncludesJs(chunkInfo)
})
}

if (Array.isArray(chunks)) {
Expand Down
9 changes: 8 additions & 1 deletion packages/webpack-plugin/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,19 @@ class LoadablePlugin {
hash: true,
publicPath: true,
assets: true,
chunks: false,
chunks: true,
modules: false,
source: false,
errorDetails: false,
timings: false,
})

stats.chunks = stats.chunks.map(chunk => ({
...chunk,
modules: [], // in case modules array is big
origins: [], // in case origins array is big
}))

const result = JSON.stringify(stats, null, 2)

if (this.opts.writeToDisk) {
Expand Down

0 comments on commit 6926e19

Please sign in to comment.