-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(types): NuxtOptionsHead
can be a function
#8319
Conversation
`NuxtOptionsHead` can be a function too. I don't know if it's ever meant to be a function in config file or not. It happily works in my `nuxt.config.ts`.
NuxtOptionsHead
can be a function
Thanks @OrkhanAlikhanov for PR. Actually it is possible to serialize head function from nuxt.config (here) but will be deprecated since serializing fns from nuxt.config is not safe |
NuxtOptionsHead
can be a functionNuxtOptionsHead
can be a function
@pi0 Thanks for merging it! I actually needed head to take function because I use Do you have any suggestions for that case? |
Actually you don't need to make it a function or order using If it is required to be changed after build you can use |
@OrkhanAlikhanov you could add it in your default layout, and use |
Jinx. 😆 |
Let me elaborate more. My goal was to push GTM script to the top of the script head so that it starts loading before nuxt scripts do. const config: NuxtConfig = {
head(): MetaInfo {
/// Injects gtm script at the top of all scripts
const injectGTM = (head: MetaInfo) => {
const gtmId = process.env.GOOGLE_TAG_MANAGER_ID
if (gtmId) {
head.script = head.script || []
head.script.unshift({
hid: 'gtm-script',
innerHTML: `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','${gtmId}');`,
})
head.__dangerouslyDisableSanitizersByTagID = head.__dangerouslyDisableSanitizersByTagID || {}
head.__dangerouslyDisableSanitizersByTagID['gtm-script'] = ['innerHTML']
}
return head
}
return injectGTM({ ... })
}, I might be over-engineering it. What do you guys think? |
Types of changes
Description
NuxtOptionsHead
can be a function too.I don't know if it's ever meant to be a function in config file or not. It happily works in my
nuxt.config.ts
.If this is going to be merged, I can fix the semantic issue.
Checklist: