mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
refactor(config): move build.crossorigin
to render.crossorigin
(#7187)
This commit is contained in:
parent
6b1faaed80
commit
c02ded2d86
@ -5,7 +5,6 @@ export default () => ({
|
|||||||
analyze: false,
|
analyze: false,
|
||||||
profile: process.argv.includes('--profile'),
|
profile: process.argv.includes('--profile'),
|
||||||
extractCSS: false,
|
extractCSS: false,
|
||||||
crossorigin: undefined,
|
|
||||||
cssSourceMap: undefined,
|
cssSourceMap: undefined,
|
||||||
ssr: undefined,
|
ssr: undefined,
|
||||||
parallel: false,
|
parallel: false,
|
||||||
|
@ -6,6 +6,7 @@ export default () => ({
|
|||||||
shouldPreload: (fileWithoutQuery, asType) => ['script', 'style'].includes(asType),
|
shouldPreload: (fileWithoutQuery, asType) => ['script', 'style'].includes(asType),
|
||||||
runInNewContext: undefined
|
runInNewContext: undefined
|
||||||
},
|
},
|
||||||
|
crossorigin: undefined,
|
||||||
resourceHints: true,
|
resourceHints: true,
|
||||||
ssr: undefined,
|
ssr: undefined,
|
||||||
ssrLog: undefined,
|
ssrLog: undefined,
|
||||||
|
@ -419,6 +419,13 @@ export function getNuxtConfig (_options) {
|
|||||||
options.build.indicator = false
|
options.build.indicator = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Remove this if statement in Nuxt 3
|
||||||
|
if (options.build.crossorigin) {
|
||||||
|
consola.warn('Using `build.crossorigin` is deprecated and will be removed in Nuxt 3. Please use `render.crossorigin` instead.')
|
||||||
|
options.render.crossorigin = options.build.crossorigin
|
||||||
|
delete options.build.crossorigin
|
||||||
|
}
|
||||||
|
|
||||||
const { timing } = options.server
|
const { timing } = options.server
|
||||||
if (timing) {
|
if (timing) {
|
||||||
options.server.timing = { total: true, ...timing }
|
options.server.timing = { total: true, ...timing }
|
||||||
|
@ -28,7 +28,6 @@ Object {
|
|||||||
"configFile": false,
|
"configFile": false,
|
||||||
},
|
},
|
||||||
"cache": false,
|
"cache": false,
|
||||||
"crossorigin": undefined,
|
|
||||||
"cssSourceMap": false,
|
"cssSourceMap": false,
|
||||||
"devMiddleware": Object {},
|
"devMiddleware": Object {},
|
||||||
"extractCSS": false,
|
"extractCSS": false,
|
||||||
@ -297,6 +296,7 @@ Object {
|
|||||||
"compressor": Object {
|
"compressor": Object {
|
||||||
"threshold": 0,
|
"threshold": 0,
|
||||||
},
|
},
|
||||||
|
"crossorigin": undefined,
|
||||||
"csp": false,
|
"csp": false,
|
||||||
"dist": Object {
|
"dist": Object {
|
||||||
"index": false,
|
"index": false,
|
||||||
|
@ -15,7 +15,6 @@ Object {
|
|||||||
"configFile": false,
|
"configFile": false,
|
||||||
},
|
},
|
||||||
"cache": false,
|
"cache": false,
|
||||||
"crossorigin": undefined,
|
|
||||||
"cssSourceMap": undefined,
|
"cssSourceMap": undefined,
|
||||||
"devMiddleware": Object {},
|
"devMiddleware": Object {},
|
||||||
"extractCSS": false,
|
"extractCSS": false,
|
||||||
@ -269,6 +268,7 @@ Object {
|
|||||||
"compressor": Object {
|
"compressor": Object {
|
||||||
"threshold": 0,
|
"threshold": 0,
|
||||||
},
|
},
|
||||||
|
"crossorigin": undefined,
|
||||||
"csp": false,
|
"csp": false,
|
||||||
"dist": Object {
|
"dist": Object {
|
||||||
"index": false,
|
"index": false,
|
||||||
@ -371,7 +371,6 @@ Object {
|
|||||||
"configFile": false,
|
"configFile": false,
|
||||||
},
|
},
|
||||||
"cache": false,
|
"cache": false,
|
||||||
"crossorigin": undefined,
|
|
||||||
"cssSourceMap": undefined,
|
"cssSourceMap": undefined,
|
||||||
"devMiddleware": Object {},
|
"devMiddleware": Object {},
|
||||||
"extractCSS": false,
|
"extractCSS": false,
|
||||||
@ -625,6 +624,7 @@ Object {
|
|||||||
"compressor": Object {
|
"compressor": Object {
|
||||||
"threshold": 0,
|
"threshold": 0,
|
||||||
},
|
},
|
||||||
|
"crossorigin": undefined,
|
||||||
"csp": false,
|
"csp": false,
|
||||||
"dist": Object {
|
"dist": Object {
|
||||||
"index": false,
|
"index": false,
|
||||||
|
@ -277,6 +277,11 @@ describe('config: options', () => {
|
|||||||
getNuxtConfig({ build: { extractCSS: { allChunks: true } } })
|
getNuxtConfig({ build: { extractCSS: { allChunks: true } } })
|
||||||
expect(consola.warn).toHaveBeenCalledWith('build.extractCSS.allChunks has no effect from v2.0.0. Please use build.optimization.splitChunks settings instead.')
|
expect(consola.warn).toHaveBeenCalledWith('build.extractCSS.allChunks has no effect from v2.0.0. Please use build.optimization.splitChunks settings instead.')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('should deprecate build.crossorigin', () => {
|
||||||
|
getNuxtConfig({ build: { crossorigin: 'use-credentials' } })
|
||||||
|
expect(consola.warn).toHaveBeenCalledWith('Using `build.crossorigin` is deprecated and will be removed in Nuxt 3. Please use `render.crossorigin` instead.')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ const defaultPushAssets = (preloadFiles, shouldPush, publicPath, options) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const { crossorigin } = options.build
|
const { crossorigin } = options.render
|
||||||
const cors = `${crossorigin ? ` crossorigin=${crossorigin};` : ''}`
|
const cors = `${crossorigin ? ` crossorigin=${crossorigin};` : ''}`
|
||||||
// `modulepreload` rel attribute only supports script-like `as` value
|
// `modulepreload` rel attribute only supports script-like `as` value
|
||||||
// https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload
|
// https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload
|
||||||
|
@ -207,7 +207,7 @@ describe('server: nuxtMiddleware', () => {
|
|||||||
}
|
}
|
||||||
context.renderRoute.mockReturnValue(result)
|
context.renderRoute.mockReturnValue(result)
|
||||||
context.options.dev = true
|
context.options.dev = true
|
||||||
context.options.build.crossorigin = 'use-credentials'
|
context.options.render.crossorigin = 'use-credentials'
|
||||||
context.options.render.http2 = {
|
context.options.render.http2 = {
|
||||||
push: true,
|
push: true,
|
||||||
shouldPush: jest.fn((fileWithoutQuery, asType) => asType === 'script')
|
shouldPush: jest.fn((fileWithoutQuery, asType) => asType === 'script')
|
||||||
|
@ -112,7 +112,7 @@ export default class SPARenderer extends BaseRenderer {
|
|||||||
|
|
||||||
// Preload initial resources
|
// Preload initial resources
|
||||||
if (Array.isArray(manifest.initial)) {
|
if (Array.isArray(manifest.initial)) {
|
||||||
const { crossorigin } = this.options.build
|
const { crossorigin } = this.options.render
|
||||||
const cors = `${crossorigin ? ` crossorigin="${crossorigin}"` : ''}`
|
const cors = `${crossorigin ? ` crossorigin="${crossorigin}"` : ''}`
|
||||||
|
|
||||||
meta.preloadFiles = manifest.initial
|
meta.preloadFiles = manifest.initial
|
||||||
|
@ -21,7 +21,7 @@ export default class SSRRenderer extends BaseRenderer {
|
|||||||
|
|
||||||
renderScripts (renderContext) {
|
renderScripts (renderContext) {
|
||||||
const scripts = renderContext.renderScripts()
|
const scripts = renderContext.renderScripts()
|
||||||
const { build: { crossorigin } } = this.options
|
const { render: { crossorigin } } = this.options
|
||||||
if (!crossorigin) {
|
if (!crossorigin) {
|
||||||
return scripts
|
return scripts
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ export default class SSRRenderer extends BaseRenderer {
|
|||||||
|
|
||||||
renderResourceHints (renderContext) {
|
renderResourceHints (renderContext) {
|
||||||
const resourceHints = renderContext.renderResourceHints()
|
const resourceHints = renderContext.renderResourceHints()
|
||||||
const { build: { crossorigin } } = this.options
|
const { render: { crossorigin } } = this.options
|
||||||
if (!crossorigin) {
|
if (!crossorigin) {
|
||||||
return resourceHints
|
return resourceHints
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
|
|||||||
|
|
||||||
plugins () {
|
plugins () {
|
||||||
const plugins = super.plugins()
|
const plugins = super.plugins()
|
||||||
const { buildOptions, options: { appTemplatePath, buildDir, modern } } = this.buildContext
|
const { buildOptions, options: { appTemplatePath, buildDir, modern, render } } = this.buildContext
|
||||||
|
|
||||||
// Generate output HTML for SSR
|
// Generate output HTML for SSR
|
||||||
if (buildOptions.ssr) {
|
if (buildOptions.ssr) {
|
||||||
@ -150,9 +150,9 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buildOptions.crossorigin) {
|
if (render.crossorigin) {
|
||||||
plugins.push(new CorsPlugin({
|
plugins.push(new CorsPlugin({
|
||||||
crossorigin: buildOptions.crossorigin
|
crossorigin: render.crossorigin
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
test/fixtures/modern/nuxt.config.js
vendored
2
test/fixtures/modern/nuxt.config.js
vendored
@ -1,7 +1,6 @@
|
|||||||
export default {
|
export default {
|
||||||
modern: true,
|
modern: true,
|
||||||
build: {
|
build: {
|
||||||
crossorigin: 'use-credentials',
|
|
||||||
filenames: {
|
filenames: {
|
||||||
app: ({ isModern }) => {
|
app: ({ isModern }) => {
|
||||||
return `${isModern ? 'modern-' : ''}[name].js`
|
return `${isModern ? 'modern-' : ''}[name].js`
|
||||||
@ -12,6 +11,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
render: {
|
render: {
|
||||||
|
crossorigin: 'use-credentials',
|
||||||
http2: {
|
http2: {
|
||||||
push: true
|
push: true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user