Created
November 6, 2020 03:17
-
-
Save potato4d/6962fb3fc2c1c3370556897ff77f9e38 to your computer and use it in GitHub Desktop.
Nuxt.js use enviroment variables in app.html file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html {{ HTML_ATTRS }}> | |
<script async src="https://www.googletagmanager.com/gtag/js?id={{ ENV.GA_ID }}"></script> | |
<script> | |
console.log(`GA_ID: {{ ENV.GA_ID }}`) | |
</script> | |
<head> | |
{{ HEAD }} | |
</head> | |
<body {{ BODY_ATTRS }}> | |
{{ APP }} | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default { | |
mode: 'universal', | |
target: 'server', | |
env: { | |
GA_ID: 12345 | |
}, | |
} |
A few years late here, but I've managed to get it to work via this PR - https://github.com/nuxt/nuxt/pull/6505/files
see https://github.com/nuxt/nuxt/tree/bb9427ee743a556761105dd0c4e7e474e922aee6/examples/custom-template for an example.
html:
<h1>Hello {{ ENV.HELLO }}</h1>
nuxt.config.js
export default {
// ...
env: {
HELLO: 'world',
},
// ...
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not working in production, any solution?