From 07e97f168ab02a49d84db7c2279432677446d1eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20K=C3=BCttner?= Date: Mon, 1 Mar 2021 21:29:51 +0100 Subject: [PATCH] fix(vue-renderer): respect injectScripts for target:static (#8912) --- packages/vue-renderer/src/renderers/ssr.js | 2 +- test/dev/full-static.test.js | 99 +++++++++++++--------- 2 files changed, 61 insertions(+), 40 deletions(-) diff --git a/packages/vue-renderer/src/renderers/ssr.js b/packages/vue-renderer/src/renderers/ssr.js index e49115beae..543c1f5c04 100644 --- a/packages/vue-renderer/src/renderers/ssr.js +++ b/packages/vue-renderer/src/renderers/ssr.js @@ -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 diff --git a/test/dev/full-static.test.js b/test/dev/full-static.test.js index 18dc3bbb60..b68ed11514 100644 --- a/test/dev/full-static.test.js +++ b/test/dev/full-static.test.js @@ -14,55 +14,76 @@ let builder let server = null let generator = null +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() + + builder = new Builder(nuxt) + builder.build = jest.fn() + generator = new Generator(nuxt, builder) + + await generator.generate() + + const serve = serveStatic(distDir) + server = http.createServer((req, res) => { + serve(req, res, finalhandler(req, res)) + }) + + port = await getPort() + server.listen(port) +} + describe('full-static', () => { - beforeAll(async () => { - const config = await loadFixture('full-static', { - generate: { - static: false, - dir: '.nuxt-generate' - } - }) - const nuxt = new Nuxt(config) - await nuxt.ready() + describe('with scripts', () => { + beforeAll(async () => await generateAndStartServer()) - builder = new Builder(nuxt) - builder.build = jest.fn() - generator = new Generator(nuxt, builder) + test('/payload (custom build.publicPath)', async () => { + const { body: html } = await rp(url('/payload')) - await generator.generate() - - const serve = serveStatic(distDir) - server = http.createServer((req, res) => { - serve(req, res, finalhandler(req, res)) + expect(html).toContain('