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

feat: support env script options #25

Merged
merged 3 commits into from
Apr 21, 2024
Merged

Conversation

harlan-zw
Copy link
Collaborator

@harlan-zw harlan-zw commented Apr 21, 2024

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

Copy link

vercel bot commented Apr 21, 2024

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

@harlan-zw harlan-zw merged commit 2f11710 into main Apr 21, 2024
2 of 3 checks passed
@harlan-zw harlan-zw deleted the feat/runtime-config-script-options branch April 21, 2024 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant