mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 09:27:13 +00:00
fix(vue-renderer): add crossorigin
for styles (#7954)
* Added ability for styles to get crossorigin if set * refactor to addAttrs Co-authored-by: Clark Du <clark.duxin@gmail.com>
This commit is contained in:
parent
9cb8a65e8d
commit
2f76702291
@ -20,34 +20,39 @@ export default class SSRRenderer extends BaseRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
renderScripts (renderContext) {
|
addAttrs (tags, referenceTag, referenceAttr) {
|
||||||
const scripts = renderContext.renderScripts()
|
const reference = referenceTag ? `<${referenceTag}` : referenceAttr
|
||||||
const { render: { crossorigin } } = this.options
|
if (!reference) {
|
||||||
if (!crossorigin) {
|
return tags
|
||||||
return scripts
|
|
||||||
}
|
}
|
||||||
return scripts.replace(
|
|
||||||
/<script/g,
|
const { render: { crossorigin } } = this.options
|
||||||
`<script crossorigin="${crossorigin}"`
|
if (crossorigin) {
|
||||||
|
tags = tags.replace(
|
||||||
|
new RegExp(reference, 'g'),
|
||||||
|
`${reference} crossorigin="${crossorigin}"`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return tags
|
||||||
|
}
|
||||||
|
|
||||||
|
renderResourceHints (renderContext) {
|
||||||
|
return this.addAttrs(renderContext.renderResourceHints(), null, 'rel="preload"')
|
||||||
|
}
|
||||||
|
|
||||||
|
renderScripts (renderContext) {
|
||||||
|
return this.addAttrs(renderContext.renderScripts(), 'script')
|
||||||
|
}
|
||||||
|
|
||||||
|
renderStyles (renderContext) {
|
||||||
|
return this.addAttrs(renderContext.renderStyles(), 'link')
|
||||||
|
}
|
||||||
|
|
||||||
getPreloadFiles (renderContext) {
|
getPreloadFiles (renderContext) {
|
||||||
return renderContext.getPreloadFiles()
|
return renderContext.getPreloadFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
renderResourceHints (renderContext) {
|
|
||||||
const resourceHints = renderContext.renderResourceHints()
|
|
||||||
const { render: { crossorigin } } = this.options
|
|
||||||
if (!crossorigin) {
|
|
||||||
return resourceHints
|
|
||||||
}
|
|
||||||
return resourceHints.replace(
|
|
||||||
/rel="preload"/g,
|
|
||||||
`rel="preload" crossorigin="${crossorigin}"`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
createRenderer () {
|
createRenderer () {
|
||||||
// Create bundle renderer for SSR
|
// Create bundle renderer for SSR
|
||||||
return createBundleRenderer(
|
return createBundleRenderer(
|
||||||
@ -144,7 +149,7 @@ export default class SSRRenderer extends BaseRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inject styles
|
// Inject styles
|
||||||
HEAD += renderContext.renderStyles()
|
HEAD += this.renderStyles(renderContext)
|
||||||
|
|
||||||
if (meta) {
|
if (meta) {
|
||||||
const prependInjectorOptions = { pbody: true }
|
const prependInjectorOptions = { pbody: true }
|
||||||
|
Loading…
Reference in New Issue
Block a user