From 79f7410e6d89d8bde1b665567500f841a05b7d91 Mon Sep 17 00:00:00 2001 From: Lukas_Skywalker Date: Wed, 22 May 2024 12:42:42 +0200 Subject: [PATCH] SHARE-9: Move script injection from nuxt config to layout Injecting the scripts inside the Nuxt config breaks the build of the application, because the environment variables are not availalble during build time. This change moves the configuration to the layout file, where the config is present. --- layouts/default.vue | 8 ++++++++ nuxt.config.js | 8 +++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/layouts/default.vue b/layouts/default.vue index 59d8af5..0dd40e3 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -69,6 +69,14 @@ export default Vue.extend({ overlay: false } }, + head() { + return { + script: [ + { src: `${this.$nuxt.context.$config.WEP_API_URL_CLIENT.replace('/v1', '')}/static/head.js` }, + { src: `${this.$nuxt.context.$config.WEP_API_URL_CLIENT.replace('/v1', '')}/static/body.js`, body: true }, + ] + } + }, computed: { redirectUrl (): string | undefined { return this.$nuxt.context.$config.REDIRECT_URL diff --git a/nuxt.config.js b/nuxt.config.js index dd98ac7..1a0aff2 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -65,10 +65,6 @@ export default { {rel: 'icon', type: 'image/png', sizes: '16x16', href: '/favicon-16x16.png'}, {rel: 'manifest', href: '/site.webmanifest'}, {rel: 'mask-icon', href: '/safari-pinned-tab.svg', color: '#000000'} - ], - script: [ - { src: `${process.env.WEP_API_URL_CLIENT.replace('/v1', '')}/static/head.js` }, - { src: `${process.env.WEP_API_URL_CLIENT.replace('/v1', '')}/static/body.js`, body: true }, ] }, publicRuntimeConfig: { @@ -97,7 +93,9 @@ export default { // HAS internal MEDIUM_SLUG: 'HAS' }, - privateRuntimeConfig: {}, + privateRuntimeConfig: { + WEP_API_URL_CLIENT: process.env.WEP_API_URL_CLIENT + }, // Global CSS: https://go.nuxtjs.dev/config-css css: [