mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
fix: correct public path in generation and start (#5202)
This commit is contained in:
parent
c6565c97c6
commit
648062c308
@ -5,7 +5,7 @@ import consola from 'consola'
|
|||||||
import devalue from '@nuxt/devalue'
|
import devalue from '@nuxt/devalue'
|
||||||
import invert from 'lodash/invert'
|
import invert from 'lodash/invert'
|
||||||
import template from 'lodash/template'
|
import template from 'lodash/template'
|
||||||
import { waitFor } from '@nuxt/utils'
|
import { waitFor, isUrl, urlJoin } from '@nuxt/utils'
|
||||||
import { createBundleRenderer } from 'vue-server-renderer'
|
import { createBundleRenderer } from 'vue-server-renderer'
|
||||||
|
|
||||||
import SPAMetaRenderer from './spa-meta'
|
import SPAMetaRenderer from './spa-meta'
|
||||||
@ -14,6 +14,9 @@ export default class VueRenderer {
|
|||||||
constructor(context) {
|
constructor(context) {
|
||||||
this.context = context
|
this.context = context
|
||||||
|
|
||||||
|
const { build: { publicPath }, router: { base } } = this.context.options
|
||||||
|
this.publicPath = isUrl(publicPath) ? publicPath : urlJoin(base, publicPath)
|
||||||
|
|
||||||
// Will be set by createRenderer
|
// Will be set by createRenderer
|
||||||
this.renderer = {
|
this.renderer = {
|
||||||
ssr: undefined,
|
ssr: undefined,
|
||||||
@ -55,11 +58,11 @@ export default class VueRenderer {
|
|||||||
|
|
||||||
renderScripts(context) {
|
renderScripts(context) {
|
||||||
if (this.context.options.modern === 'client') {
|
if (this.context.options.modern === 'client') {
|
||||||
const { publicPath, crossorigin } = this.context.options.build
|
|
||||||
const scriptPattern = /<script[^>]*?src="([^"]*?)"[^>]*?>[^<]*?<\/script>/g
|
const scriptPattern = /<script[^>]*?src="([^"]*?)"[^>]*?>[^<]*?<\/script>/g
|
||||||
return context.renderScripts().replace(scriptPattern, (scriptTag, jsFile) => {
|
return context.renderScripts().replace(scriptPattern, (scriptTag, jsFile) => {
|
||||||
const legacyJsFile = jsFile.replace(publicPath, '')
|
const legacyJsFile = jsFile.replace(this.publicPath, '')
|
||||||
const modernJsFile = this.assetsMapping[legacyJsFile]
|
const modernJsFile = this.assetsMapping[legacyJsFile]
|
||||||
|
const { build: { crossorigin } } = this.context.options
|
||||||
const cors = `${crossorigin ? ` crossorigin="${crossorigin}"` : ''}`
|
const cors = `${crossorigin ? ` crossorigin="${crossorigin}"` : ''}`
|
||||||
const moduleTag = modernJsFile
|
const moduleTag = modernJsFile
|
||||||
? scriptTag
|
? scriptTag
|
||||||
@ -95,14 +98,14 @@ export default class VueRenderer {
|
|||||||
|
|
||||||
renderSsrResourceHints(context) {
|
renderSsrResourceHints(context) {
|
||||||
if (this.context.options.modern === 'client') {
|
if (this.context.options.modern === 'client') {
|
||||||
const { publicPath, crossorigin } = this.context.options.build
|
|
||||||
const linkPattern = /<link[^>]*?href="([^"]*?)"[^>]*?as="script"[^>]*?>/g
|
const linkPattern = /<link[^>]*?href="([^"]*?)"[^>]*?as="script"[^>]*?>/g
|
||||||
return context.renderResourceHints().replace(linkPattern, (linkTag, jsFile) => {
|
return context.renderResourceHints().replace(linkPattern, (linkTag, jsFile) => {
|
||||||
const legacyJsFile = jsFile.replace(publicPath, '')
|
const legacyJsFile = jsFile.replace(this.publicPath, '')
|
||||||
const modernJsFile = this.assetsMapping[legacyJsFile]
|
const modernJsFile = this.assetsMapping[legacyJsFile]
|
||||||
if (!modernJsFile) {
|
if (!modernJsFile) {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
const { crossorigin } = this.context.options.build
|
||||||
const cors = `${crossorigin ? ` crossorigin="${crossorigin}"` : ''}`
|
const cors = `${crossorigin ? ` crossorigin="${crossorigin}"` : ''}`
|
||||||
return linkTag.replace('rel="preload"', `rel="modulepreload"${cors}`).replace(legacyJsFile, modernJsFile)
|
return linkTag.replace('rel="preload"', `rel="modulepreload"${cors}`).replace(legacyJsFile, modernJsFile)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user