refactor(config): move build.crossorigin to render.crossorigin (#7187)

This commit is contained in:
Xin Du (Clark) 2020-04-07 10:38:49 +01:00 committed by GitHub
parent 6b1faaed80
commit c02ded2d86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 25 additions and 13 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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 }

View File

@ -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,

View File

@ -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,

View File

@ -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.')
})
}) })
}) })

View File

@ -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

View File

@ -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')

View File

@ -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

View File

@ -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
} }

View File

@ -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
})) }))
} }

View File

@ -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
} }