mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 23:52:06 +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) {
|
||||
const scripts = renderContext.renderScripts()
|
||||
const { render: { crossorigin } } = this.options
|
||||
if (!crossorigin) {
|
||||
return scripts
|
||||
addAttrs (tags, referenceTag, referenceAttr) {
|
||||
const reference = referenceTag ? `<${referenceTag}` : referenceAttr
|
||||
if (!reference) {
|
||||
return tags
|
||||
}
|
||||
return scripts.replace(
|
||||
/<script/g,
|
||||
`<script crossorigin="${crossorigin}"`
|
||||
)
|
||||
|
||||
const { render: { crossorigin } } = this.options
|
||||
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) {
|
||||
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 () {
|
||||
// Create bundle renderer for SSR
|
||||
return createBundleRenderer(
|
||||
@ -144,7 +149,7 @@ export default class SSRRenderer extends BaseRenderer {
|
||||
}
|
||||
|
||||
// Inject styles
|
||||
HEAD += renderContext.renderStyles()
|
||||
HEAD += this.renderStyles(renderContext)
|
||||
|
||||
if (meta) {
|
||||
const prependInjectorOptions = { pbody: true }
|
||||
|
Loading…
Reference in New Issue
Block a user