Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore single css chunk (close #688) #689

Merged
merged 1 commit into from
Jan 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -20,12 +20,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.outputAsset) {
Expand Down