Skip to content
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

Document .env / runtimeConfig usage for all scripts #167

Open
MickL opened this issue Jul 20, 2024 · 3 comments
Open

Document .env / runtimeConfig usage for all scripts #167

MickL opened this issue Jul 20, 2024 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@MickL
Copy link
Contributor

MickL commented Jul 20, 2024

Most integratiosn like Cloudflare Web Analytics or Google Analytics seem to be configurable by a very convinient way using .env file and nuxt config:

export default defineNuxtConfig({
  scripts: {
    registry: {
      googleAnalytics: true,
    }
  },
  runtimeConfig: {
    public: {
      scripts: {
        googleAnalytics: {
          id: '', // NUXT_PUBLIC_SCRIPTS_GOOGLE_ANALYTICS_ID
        },
      },
    },
  },
})

However other scripts like Google Maps or Stripe require to add the key manually:

Google Maps:

<script setup lang="ts">
const { $script } = useScriptGoogleMaps({
  apiKey: 'key' // <---- This shouldnt be needed if configured in runtimeConfig 
})
// ...
</script>

Stripe:

<script setup lang="ts">
const { $script } = useScriptStripe()
onMounted(() => {
  $script.then(({ Stripe }) => {
    const stripe = Stripe('YOUR_STRIPE_KEY'); // <---- This shouldnt be needed if configured in runtimeConfig
    // ...
  })
})
// ...
</script>

Can we have all integrations configurable with .env and runtime config? Or maybe they are already but it is not documented?

@MickL MickL changed the title Configure all integrations by .env Configure all integrations by .env and runtimeConfig Jul 20, 2024
@harlan-zw
Copy link
Collaborator

Thanks for raising this, afaik it should just work but yes it will throw a TypeScript error. This does need to be fixed, I think we'd need to do runtime type augmentation if the env is provided.

@harlan-zw harlan-zw added the bug Something isn't working label Jul 20, 2024
@MickL
Copy link
Contributor Author

MickL commented Jul 20, 2024

If it works then it is just not documentated for some integrations, maybe you got it wrong it shouldnt be a bug :) It is either a feature request or docs missing.

@harlan-zw harlan-zw added documentation Improvements or additions to documentation and removed bug Something isn't working labels Sep 3, 2024
@harlan-zw
Copy link
Collaborator

I've switched this to a docs issue as the typescript issue should be fixed.

All registry scripts and components requiring any type of key should be configurable using env keys which will need to be documented.

@harlan-zw harlan-zw changed the title Configure all integrations by .env and runtimeConfig Document .env / runtimeConfig usage for all scripts Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants