mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(webpack): avoid using node_modules
for chunk names (#7906)
[release]
This commit is contained in:
parent
68b9183c4c
commit
44471ec9df
@ -66,13 +66,13 @@ 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',
|
||||
name: 'node_modules/commons',
|
||||
name: 'vendors/commons',
|
||||
priority: 10
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.dev && splitChunks.name === undefined) {
|
||||
const nameMap = { default: 'commons', vendors: 'node_modules' }
|
||||
const nameMap = { default: 'commons' }
|
||||
splitChunks.name = (_module, chunks, cacheGroup) => {
|
||||
// Map chunks to names
|
||||
const names = chunks
|
||||
|
@ -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/node_modules/commons.js')
|
||||
expect(response).toContain('script nomodule crossorigin="use-credentials" src="/_nuxt/vendors/commons.js')
|
||||
})
|
||||
|
||||
test('should contain module modern resources', async () => {
|
||||
const { body: response } = await rp(url('/'))
|
||||
expect(response).toContain('<script type="module" crossorigin="use-credentials" src="/_nuxt/app.modern.js"')
|
||||
expect(response).toContain('<script type="module" crossorigin="use-credentials" src="/_nuxt/node_modules/commons.modern.js"')
|
||||
expect(response).toContain('<script type="module" crossorigin="use-credentials" src="/_nuxt/vendors/commons.modern.js"')
|
||||
})
|
||||
|
||||
test('should contain module preload resources', async () => {
|
||||
const { body: response } = await rp(url('/'))
|
||||
expect(response).toContain('<link rel="modulepreload" crossorigin="use-credentials" href="/_nuxt/app.modern.js" as="script">')
|
||||
expect(response).toContain('<link rel="modulepreload" crossorigin="use-credentials" href="/_nuxt/node_modules/commons.modern.js" as="script">')
|
||||
expect(response).toContain('<link rel="modulepreload" crossorigin="use-credentials" href="/_nuxt/vendors/commons.modern.js" as="script">')
|
||||
})
|
||||
|
||||
test('should contain module http2 pushed resources', async () => {
|
||||
const { headers: { link } } = await rp(url('/'))
|
||||
expect(link).toEqual([
|
||||
'</_nuxt/runtime.modern.js>; rel=modulepreload; crossorigin=use-credentials; as=script',
|
||||
'</_nuxt/node_modules/commons.modern.js>; rel=modulepreload; crossorigin=use-credentials; as=script',
|
||||
'</_nuxt/vendors/commons.modern.js>; rel=modulepreload; crossorigin=use-credentials; as=script',
|
||||
'</_nuxt/app.modern.js>; rel=modulepreload; crossorigin=use-credentials; as=script',
|
||||
`</_nuxt/pages/index.modern.js>; rel=modulepreload; crossorigin=use-credentials; as=script`
|
||||
].join(', '))
|
||||
|
@ -24,13 +24,13 @@ describe('modern server mode', () => {
|
||||
test('should use legacy resources by default', async () => {
|
||||
const { body: response } = await rp(url('/'))
|
||||
expect(response).toContain('/_nuxt/app.js')
|
||||
expect(response).toContain('/_nuxt/node_modules/commons.js')
|
||||
expect(response).toContain('/_nuxt/vendors/commons.js')
|
||||
})
|
||||
|
||||
test('should use modern resources for modern resources', async () => {
|
||||
const { body: response } = await rp(url('/'), { headers: { 'user-agent': modernUA } })
|
||||
expect(response).toContain('/_nuxt/app.modern.js')
|
||||
expect(response).toContain('/_nuxt/node_modules/commons.modern.js')
|
||||
expect(response).toContain('/_nuxt/vendors/commons.modern.js')
|
||||
})
|
||||
|
||||
test('should include es6 syntax in modern resources', async () => {
|
||||
@ -47,7 +47,7 @@ describe('modern server mode', () => {
|
||||
const { headers: { link } } = await rp(url('/'))
|
||||
expect(link).toEqual([
|
||||
'</_nuxt/runtime.js>; rel=preload; crossorigin=use-credentials; as=script',
|
||||
'</_nuxt/node_modules/commons.js>; rel=preload; crossorigin=use-credentials; as=script',
|
||||
'</_nuxt/vendors/commons.js>; rel=preload; crossorigin=use-credentials; as=script',
|
||||
'</_nuxt/app.js>; rel=preload; crossorigin=use-credentials; as=script',
|
||||
`</_nuxt/${wChunk('pages/index.js')}>; rel=preload; crossorigin=use-credentials; as=script`
|
||||
].join(', '))
|
||||
@ -59,7 +59,7 @@ describe('modern server mode', () => {
|
||||
})
|
||||
expect(link).toEqual([
|
||||
'</_nuxt/runtime.modern.js>; rel=preload; crossorigin=use-credentials; as=script',
|
||||
'</_nuxt/node_modules/commons.modern.js>; rel=preload; crossorigin=use-credentials; as=script',
|
||||
'</_nuxt/vendors/commons.modern.js>; rel=preload; crossorigin=use-credentials; as=script',
|
||||
'</_nuxt/app.modern.js>; rel=preload; crossorigin=use-credentials; as=script',
|
||||
`</_nuxt/pages/index.modern.js>; rel=preload; crossorigin=use-credentials; as=script`
|
||||
].join(', '))
|
||||
|
@ -24,26 +24,26 @@ describe('modern client mode (SPA)', () => {
|
||||
test('should contain nomodule legacy resources', async () => {
|
||||
const { body: response } = await rp(url('/'))
|
||||
expect(response).toContain('src="/_nuxt/app.js" crossorigin="use-credentials" nomodule')
|
||||
expect(response).toContain('src="/_nuxt/node_modules/commons.js" crossorigin="use-credentials" nomodule')
|
||||
expect(response).toContain('src="/_nuxt/vendors/commons.js" crossorigin="use-credentials" nomodule')
|
||||
})
|
||||
|
||||
test('should contain module modern resources', async () => {
|
||||
const { body: response } = await rp(url('/'))
|
||||
expect(response).toContain('<script src="/_nuxt/app.modern.js" type="module" crossorigin="use-credentials"')
|
||||
expect(response).toContain('<script src="/_nuxt/node_modules/commons.modern.js" type="module" crossorigin="use-credentials"')
|
||||
expect(response).toContain('<script src="/_nuxt/vendors/commons.modern.js" type="module" crossorigin="use-credentials"')
|
||||
})
|
||||
|
||||
test('should contain legacy preload resources', async () => {
|
||||
const { body: response } = await rp(url('/'))
|
||||
expect(response).toContain('<link rel="preload" crossorigin="use-credentials" href="/_nuxt/app.js" as="script">')
|
||||
expect(response).toContain('<link rel="preload" crossorigin="use-credentials" href="/_nuxt/node_modules/commons.js" as="script">')
|
||||
expect(response).toContain('<link rel="preload" crossorigin="use-credentials" href="/_nuxt/vendors/commons.js" as="script">')
|
||||
})
|
||||
|
||||
test('should contain legacy http2 pushed resources', async () => {
|
||||
const { headers: { link } } = await rp(url('/'))
|
||||
expect(link).toEqual([
|
||||
'</_nuxt/runtime.js>; rel=preload; crossorigin=use-credentials; as=script',
|
||||
'</_nuxt/node_modules/commons.js>; rel=preload; crossorigin=use-credentials; as=script',
|
||||
'</_nuxt/vendors/commons.js>; rel=preload; crossorigin=use-credentials; as=script',
|
||||
'</_nuxt/app.js>; rel=preload; crossorigin=use-credentials; as=script'
|
||||
].join(', '))
|
||||
})
|
||||
@ -51,7 +51,7 @@ describe('modern client mode (SPA)', () => {
|
||||
test('should contain modern preload resources', async () => {
|
||||
const { body: response } = await rp(url('/'), { headers: { 'user-agent': modernUA } })
|
||||
expect(response).toContain('<link rel="modulepreload" crossorigin="use-credentials" href="/_nuxt/app.modern.js" as="script">')
|
||||
expect(response).toContain('<link rel="modulepreload" crossorigin="use-credentials" href="/_nuxt/node_modules/commons.modern.js" as="script">')
|
||||
expect(response).toContain('<link rel="modulepreload" crossorigin="use-credentials" href="/_nuxt/vendors/commons.modern.js" as="script">')
|
||||
})
|
||||
|
||||
test('should contain safari nomodule fix', async () => {
|
||||
@ -63,7 +63,7 @@ describe('modern client mode (SPA)', () => {
|
||||
const { headers: { link } } = await rp(url('/'), { headers: { 'user-agent': modernUA } })
|
||||
expect(link).toEqual([
|
||||
'</_nuxt/runtime.modern.js>; rel=modulepreload; crossorigin=use-credentials; as=script',
|
||||
'</_nuxt/node_modules/commons.modern.js>; rel=modulepreload; crossorigin=use-credentials; as=script',
|
||||
'</_nuxt/vendors/commons.modern.js>; rel=modulepreload; crossorigin=use-credentials; as=script',
|
||||
'</_nuxt/app.modern.js>; rel=modulepreload; crossorigin=use-credentials; as=script'
|
||||
].join(', '))
|
||||
})
|
||||
|
@ -35,7 +35,7 @@ function spaTests ({ isHashMode }) {
|
||||
test('/ (include preload and prefetch resources)', async () => {
|
||||
const { head } = await renderRoute('/')
|
||||
expect(head).toMatch('<link rel="preload" href="/_nuxt/runtime.js" as="script">')
|
||||
expect(head).toMatch('<link rel="preload" href="/_nuxt/node_modules/commons.js" as="script">')
|
||||
expect(head).toMatch('<link rel="preload" href="/_nuxt/vendors/commons.js" as="script">')
|
||||
expect(head).toMatch('<link rel="preload" href="/_nuxt/app.js" as="script">')
|
||||
expect(head).toMatch(`<link rel="prefetch" href="/_nuxt/${wChunk('pages/custom.js')}">`)
|
||||
expect(head).toMatch(`<link rel="prefetch" href="/_nuxt/${wChunk('pages/error-handler-async.js')}">`)
|
||||
|
Loading…
Reference in New Issue
Block a user