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

Module improvements #3

Closed
pi0 opened this issue Sep 15, 2022 · 6 comments · Fixed by #5
Closed

Module improvements #3

pi0 opened this issue Sep 15, 2022 · 6 comments · Fixed by #5
Assignees

Comments

@pi0
Copy link

pi0 commented Sep 15, 2022

Hi! Following up nuxt/modules#427 i've made a quick review:

Rest seems a nice module 🚀

@ijkml ijkml self-assigned this Sep 15, 2022
@ijkml
Copy link
Owner

ijkml commented Sep 15, 2022

Hi, thanks for the review. I'll get to work on it, immediately.

Please, to clarify, how do you mean mock? Mock (as in fake) the umami function on the server?

Thank you.

@pi0
Copy link
Author

pi0 commented Sep 15, 2022

An empty function should do the trick. It is to avoid breaking SSR code if someone calls $umami wrongly.

@ijkml
Copy link
Owner

ijkml commented Sep 16, 2022

Thank you.

Nearly there... Created the mock, and renamed the plugin to plugin.client. But now I run into an issue, the module fails to resolve the plugin, unless I change it to 'plugin.client' (which defeats the whole purpose, I'll admit).

Here's the addPlugin function:

addPlugin({ src: resolve(runtimeDir, 'plugin.client'), mode: 'client' });

And the error:
Error screenshot

@ijkml
Copy link
Owner

ijkml commented Sep 19, 2022

Hi @pi0
It seems file name modifiers are not working as expected when using nuxt/kit.

So, what I did was:

  • provide the mock as default
  • load script (returns Promise<false> if window is undefined else Promise<HTMLScriptElement>)
    • if false or error, do nothing (ssr)
    • else replace mock with umami

That way umami is mocked if used by mistake, and a warning is logged.

Please let me know what you think, and what other improvements I can make.

https://github.com/ijkml/nuxt-umami/tree/client-only-patch

@pi0
Copy link
Author

pi0 commented Sep 20, 2022

Hi dear @ijkml. I have checked client-only patch! It is in fact a much nicer solution to use one plugin with ssr fallback. Only as a tip, instead of using process.env.NODE_ENV !== 'production';, use if (process.client) (inside) the implementation. This way you can hint rollup to treeshake client code from server bundle. call to load-script for example can be done like this.

@ijkml
Copy link
Owner

ijkml commented Sep 20, 2022

Thank you, @pi0 for your time and patience 🙏

Please have one more look: #5

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 a pull request may close this issue.

2 participants