diff --git a/packages/config/src/config/build.js b/packages/config/src/config/build.js index 94170a3d026e..1a2e63ec27c5 100644 --- a/packages/config/src/config/build.js +++ b/packages/config/src/config/build.js @@ -62,12 +62,8 @@ export default () => ({ minimizer: undefined, splitChunks: { chunks: 'all', - name: undefined, - cacheGroups: { - default: { - name: undefined - } - } + automaticNameDelimiter: '/', + cacheGroups: {} } }, splitChunks: { diff --git a/packages/config/test/__snapshots__/options.test.js.snap b/packages/config/test/__snapshots__/options.test.js.snap index 3acdfbecb5cb..d3861ba2538f 100644 --- a/packages/config/test/__snapshots__/options.test.js.snap +++ b/packages/config/test/__snapshots__/options.test.js.snap @@ -113,13 +113,9 @@ Object { "minimizer": undefined, "runtimeChunk": "single", "splitChunks": Object { - "cacheGroups": Object { - "default": Object { - "name": undefined, - }, - }, + "automaticNameDelimiter": "/", + "cacheGroups": Object {}, "chunks": "all", - "name": undefined, }, }, "optimizeCSS": false, diff --git a/packages/config/test/config/__snapshots__/index.test.js.snap b/packages/config/test/config/__snapshots__/index.test.js.snap index 317cdb2fd1a5..a37a2ba91c2a 100644 --- a/packages/config/test/config/__snapshots__/index.test.js.snap +++ b/packages/config/test/config/__snapshots__/index.test.js.snap @@ -89,13 +89,9 @@ Object { "minimizer": undefined, "runtimeChunk": "single", "splitChunks": Object { - "cacheGroups": Object { - "default": Object { - "name": undefined, - }, - }, + "automaticNameDelimiter": "/", + "cacheGroups": Object {}, "chunks": "all", - "name": undefined, }, }, "optimizeCSS": undefined, @@ -469,13 +465,9 @@ Object { "minimizer": undefined, "runtimeChunk": "single", "splitChunks": Object { - "cacheGroups": Object { - "default": Object { - "name": undefined, - }, - }, + "automaticNameDelimiter": "/", + "cacheGroups": Object {}, "chunks": "all", - "name": undefined, }, }, "optimizeCSS": undefined, diff --git a/packages/webpack/src/config/client.js b/packages/webpack/src/config/client.js index 58745992d70e..6e964ee226f4 100644 --- a/packages/webpack/src/config/client.js +++ b/packages/webpack/src/config/client.js @@ -66,14 +66,14 @@ export default class WebpackClientConfig extends WebpackBaseConfig { cacheGroups.commons = { test: /node_modules[\\/](vue|vue-loader|vue-router|vuex|vue-meta|core-js|@babel\/runtime|axios|webpack|setimmediate|timers-browserify|process|regenerator-runtime|cookie|js-cookie|is-buffer|dotprop|nuxt\.js)[\\/]/, chunks: 'all', - priority: 10, - name: true, - automaticNameDelimiter: '/' + name: 'node_modules/commons', + priority: 10 } } - if (!this.dev && cacheGroups.default && cacheGroups.default.name === undefined) { - cacheGroups.default.name = (_module, chunks) => { + if (!this.dev && splitChunks.name === undefined) { + const nameMap = { default: 'commons', vendors: 'node_modules' } + splitChunks.name = (_module, chunks, cacheGroup) => { // Map chunks to names const names = chunks .map(c => c.name || '') @@ -85,15 +85,9 @@ export default class WebpackClientConfig extends WebpackBaseConfig { .filter(Boolean) .sort() - // 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] + // Fallback to webpack chunk name or generated cache group key + if (names.length < 2) { + return chunks[0].name } // Use compact name for concatinated modules @@ -101,7 +95,8 @@ export default class WebpackClientConfig extends WebpackBaseConfig { if (compactName.length > 32) { compactName = hash(compactName) } - return 'commons/' + compactName + const prefix = nameMap[cacheGroup || 'default'] || cacheGroup + return prefix + '/' + compactName } } diff --git a/test/dev/modern.client.test.js b/test/dev/modern.client.test.js index 88f531426fed..2c838710176f 100644 --- a/test/dev/modern.client.test.js +++ b/test/dev/modern.client.test.js @@ -16,26 +16,26 @@ describe('modern client mode (SSR)', () => { test('should contain nomodule legacy resources', async () => { const { body: response } = await rp(url('/')) expect(response).toContain('script nomodule crossorigin="use-credentials" src="/_nuxt/app.js') - expect(response).toContain('script nomodule crossorigin="use-credentials" src="/_nuxt/commons/app.js') + expect(response).toContain('script nomodule crossorigin="use-credentials" src="/_nuxt/node_modules/commons.js') }) test('should contain module modern resources', async () => { const { body: response } = await rp(url('/')) expect(response).toContain(' diff --git a/test/fixtures/shared-chunk/components/shared-vendor.vue b/test/fixtures/shared-chunk/components/shared-vendor.vue index 37a84bc925df..6449431cbcd6 100644 --- a/test/fixtures/shared-chunk/components/shared-vendor.vue +++ b/test/fixtures/shared-chunk/components/shared-vendor.vue @@ -5,15 +5,5 @@ diff --git a/test/fixtures/shared-chunk/nuxt.config.js b/test/fixtures/shared-chunk/nuxt.config.js index 3c6e6c4a919a..140850c61363 100644 --- a/test/fixtures/shared-chunk/nuxt.config.js +++ b/test/fixtures/shared-chunk/nuxt.config.js @@ -1,4 +1,3 @@ export default { - components: true, - modern: true + components: true }