mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
fix(webpack): fallback for empty chunk name (#7667)
[release] Co-authored-by: pooya parsa <pyapar@gmail.com>
This commit is contained in:
parent
e3821ba78c
commit
b4ffdab790
@ -74,22 +74,33 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
|
|||||||
|
|
||||||
if (!this.dev && cacheGroups.default && cacheGroups.default.name === undefined) {
|
if (!this.dev && cacheGroups.default && cacheGroups.default.name === undefined) {
|
||||||
cacheGroups.default.name = (_module, chunks) => {
|
cacheGroups.default.name = (_module, chunks) => {
|
||||||
// Use default name for single chunks
|
// Map chunks to names
|
||||||
if (chunks.length === 1) {
|
const names = chunks
|
||||||
return chunks[0].name || ''
|
.map(c => c.name || '')
|
||||||
}
|
.map(name => name
|
||||||
// Use compact name for concatinated modules
|
.replace(/[/\\]/g, '.')
|
||||||
let compactName = chunks
|
.replace(/_/g, '')
|
||||||
.filter(c => c.name)
|
.replace('pages.', '')
|
||||||
.map(c => c.name)
|
)
|
||||||
|
.filter(Boolean)
|
||||||
.sort()
|
.sort()
|
||||||
.map(name => name.replace(/[/\\]/g, '.').replace(/_/g, '').replace('pages.', ''))
|
|
||||||
.join('~')
|
|
||||||
|
|
||||||
|
// Fixes https://github.com/nuxt/nuxt.js/issues/7665
|
||||||
|
// TODO: We need a reproduction for this case (test/fixtures/shared-chunk)
|
||||||
|
if (!names.length) {
|
||||||
|
return 'commons/default'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Single chunk is not common
|
||||||
|
if (names.length === 1) {
|
||||||
|
return names[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use compact name for concatinated modules
|
||||||
|
let compactName = names.join('~')
|
||||||
if (compactName.length > 32) {
|
if (compactName.length > 32) {
|
||||||
compactName = hash(compactName)
|
compactName = hash(compactName)
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'commons/' + compactName
|
return 'commons/' + compactName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
test/fixtures/shared-chunk/components/lazy.vue
vendored
Normal file
5
test/fixtures/shared-chunk/components/lazy.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
Lazy Components
|
||||||
|
</div>
|
||||||
|
</template>
|
3
test/fixtures/shared-chunk/nuxt.config.js
vendored
3
test/fixtures/shared-chunk/nuxt.config.js
vendored
@ -1,3 +1,4 @@
|
|||||||
export default {
|
export default {
|
||||||
components: true
|
components: true,
|
||||||
|
modern: true
|
||||||
}
|
}
|
||||||
|
9
test/fixtures/shared-chunk/pages/index.vue
vendored
9
test/fixtures/shared-chunk/pages/index.vue
vendored
@ -1,5 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
|
<MyLazyComponent />
|
||||||
<SharedVendor />
|
<SharedVendor />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
MyLazyComponent: () => import('~/components/lazy.vue')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user