nuxt / scripts

Plug-and-play script optimization for Nuxt applications. (Public Preview)
https://scripts.nuxt.com
MIT License
134 stars 9 forks source link

feat: support env script options #25

Closed harlan-zw closed 2 months ago

harlan-zw commented 2 months ago

Allow users to load scripts without publishing script options.

For example, all of these are possible:

  1. Use Scripts Register
export default defineNuxtConfig({
  scripts: {
    register: {
      googleAnalytics: { id: 'GA-123456789-1' }
    }
  },
})
  1. Use Env & Scripts Register
export default defineNuxtConfig({
  scripts: {
    register: {
      googleAnalytics: true
    }
  },
  runtimeConfig: {
    public: {
      scripts: {
        googleAnalytics: {
          id: '',
        },
      },
    },
  },
})
NUXT_PUBLIC_SCRIPTS_GOOGLE_ANALYTICS_ID=GA-123456789-1
  1. Use Env & Composable
const { gtag } = useScriptGoogleAnalytics()
export default defineNuxtConfig({
  runtimeConfig: {
    public: {
      scripts: {
        googleAnalytics: {
          id: '',
        },
      },
    },
  },
})
NUXT_PUBLIC_SCRIPTS_GOOGLE_ANALYTICS_ID=GA-123456789-1
vercel[bot] commented 2 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
scripts-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 21, 2024 8:41am