fix(vue-renderer): respect injectScripts for target:static (#8912)

This commit is contained in:
Hannes Küttner 2021-03-01 21:29:51 +01:00 committed by GitHub
parent 880fe4abd7
commit 07e97f168a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 40 deletions

View File

@ -177,7 +177,7 @@ export default class SSRRenderer extends BaseRenderer {
const shouldHashCspScriptSrc = csp && (csp.unsafeInlineCompatibility || !containsUnsafeInlineScriptSrc)
const inlineScripts = []
if (renderContext.staticAssetsBase) {
if (shouldInjectScripts && renderContext.staticAssetsBase) {
const preloadScripts = []
renderContext.staticAssets = []
const { staticAssetsBase, url, nuxt, staticAssets } = renderContext

View File

@ -14,13 +14,13 @@ let builder
let server = null
let generator = null
describe('full-static', () => {
beforeAll(async () => {
const generateAndStartServer = async (overrides) => {
const config = await loadFixture('full-static', {
generate: {
static: false,
dir: '.nuxt-generate'
}
},
...(overrides || {})
})
const nuxt = new Nuxt(config)
await nuxt.ready()
@ -38,7 +38,11 @@ describe('full-static', () => {
port = await getPort()
server.listen(port)
})
}
describe('full-static', () => {
describe('with scripts', () => {
beforeAll(async () => await generateAndStartServer())
test('/payload (custom build.publicPath)', async () => {
const { body: html } = await rp(url('/payload'))
@ -65,4 +69,21 @@ describe('full-static', () => {
afterAll(async () => {
await server.close()
})
})
describe('without scripts', () => {
beforeAll(async () => await generateAndStartServer({ render: { injectScripts: false } }))
test('should not inject scripts', async () => {
const { body: html } = await rp(url('/payload'))
expect(html).not.toContain('<script')
expect(html).not.toContain('<link')
})
// Close server and ask nuxt to stop listening to file changes
afterAll(async () => {
await server.close()
})
})
})