Closed BlueBazze closed 4 months ago
Looks good to me
@dargmuesli Im working on it. And was wondering why the moduleOptions is being printed to a .ts file in the build directory. https://github.com/dargmuesli/nuxt-cookie-control/blob/master/src/module.ts#L59-L68
The only place it is being used is in the plugin. https://github.com/dargmuesli/nuxt-cookie-control/blob/master/src/runtime/plugin.ts#L9
Another workaround: https://nuxt.com/docs/guide/going-further/modules#exposing-options-to-runtime
module.ts
nuxt.options.runtimeConfig.cookieControl = moduleOptions
plugin.ts
const plugin: Plugin<{ cookies: State }> = defineNuxtPlugin((_nuxtApp) => {
console.log('moduleOptions', _nuxtApp.$config.cookieControl)
}
Migrating to runtimeConfig
looks good to me, the file output was implemented because this module was one of the first to migrate to Nuxt 3, at a time at which recipes or other documentations were not available yet. Do you want to create a separate PR for that?
Sorry, was on another task. I see that you already did it - Well done.
I didn't manage to get runtimeConfig
running though due to typing issues. The linter sourced from .nuxt
(string
properties only) and types
(proper types) which led to type incompatibilities. Maybe you can figure out a way to have correct types in all places.
I'll take a look within the next week
@dargmuesli Done, fixed with https://github.com/dargmuesli/nuxt-cookie-control/pull/213
declare module '@nuxt/schema' {
interface PublicRuntimeConfig {
cookieControl: ModuleOptions
}
}
I also moved it to public runtime config. Since the plugin is being run on the client side aswell. In case you want to change it to the non-public runtime config later, just simply remove the "Public" part of "PublicRuntimeConfig"
And the line
nuxt.options.runtimeConfig.public.cookieControl = moduleOptions
I've placed at the bottom of the module setup, since the moduleOptions are being changed during setup.
Describe the feature
Would be nice with having cookies typed.
I wanna know if this is wanted, before making any pr.
I am working on a composable for my project, i'd like to have some kind of selector for which cookie i am targeting with the composable. Having the cookie id's as string literals instead of being typed as strings would catch misspelling.
It would probably not be anything major, just a new types file, a generator for this typing would be fairly small probably 10 lines.
Additional information
Final checks