-
Notifications
You must be signed in to change notification settings - Fork 3
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
[feedback] experimentalUseVirtualModules
#273
Comments
We have monorepo setup where i18n is separate package, exporting vite plugin and compiled messages output. App launches using vite plugin from i18n package: import { join } from 'node:path'
import { paraglide } from '@inlang/paraglide-vite'
/** @param {string} path */
const resolve = (path) => join(import.meta.dirname, path)
/** @return {import('vite').PluginOption} */
export const i18nPlugin = () =>
paraglide({
project: resolve('../project.inlang'),
outdir: resolve('./paraglide'),
}) After enabling Could there be a way to keep type and js generation together? Not all things support vite or specifically paraglide vite plugin see. As a workaround we use paraglide CLI to generate output manually, not using it bundler plugin. For our case i18n package is shared, so when running different projects output should not change. Speaking of CLI will it also get something similar to |
What version of paraglide-next can test this? |
That would be a vite limitation. The limitation seems reasonable though. Vite can't know that dependencies use virtual modules. If you use Paraglide JS in a library, I strongly recommend to not use virtual modules.
The virtual modules would be an opt-in flag. Else, Paraglide JS defaults to emitting JS with JSDoc/TS declaration files.
Yes. I plan to merge bundler logic into the paraglide-js package. If that happens, bundler logic (like emitting declaration files) could easily be adapted for the CLI too. In general, I plan to expose the Paraglide JS compiler for v2. You, and everyone else, will be able to leverage the Paraglide compiler to build your own scripts on top. |
The library code is not bundled, its source code, which passes directly through vite, if it is not possible to resolve relative paths correctly, maybe explicit import like
Will it be possible to enable both at the same time? Now its one or another. Other than that, looking forward to v2 🚀 |
Great idea. Instead of having |
I'm not sure if I'm doing something wrong, but using Reproduction
I also tried reproducing this with the example app provided in the monorepo, but I had so many different errors after downloading the relevant directory using this tool https://download-directory.github.io that i gave up. Am I missing something or doing something wrong? |
Can you create a reproduction repository that I can clone?
This import looks suspicious. There should not be an |
Sure, here you go: https://github.com/manuel3108/paraglide-virtual-module-repro. I tried to split everything up into separate commits, so you can clearly see what I changed. After cloning and installing deps run |
@samuelstroschein, maybe it’s just me, but when I enable TypeError: __vite_ssr_import_6__.new_message is not a function It seems like the messages aren’t being regenerated properly when using |
@samuelstroschein, oh, you’re already aware of this issue — great to hear that! Thanks for your incredible work! |
@ everyone in this thread: What benefit do you hope to get with virtual modules? I am currently implementing Paraglide JS 2.0 which seems to eliminate the benefits of the virtual modules flag:
Is there a benefit aside of optimized tree-shaking and ts declaration files that i am missing? |
Personally I don't mind either. Sveltekit generates actual files in DEV and most people aren't bothered of it. Having actual files does makes it simpler to understand the output and resolution for modules in complex setups (my monorepo setup comment) One possible benefit might be performance for HRM/memory with a lot of files, but that is just a wild guess and might not even matter.
Can you elaborate about that? One message, one javascript module file? |
Yes. That helps bundlers tree-shake more efficiently. The output is configurable. The old default, per locale modules, is still supported. |
Goal would be to not at all emit files in any user facing directories like |
Compiling Paraglide into I think there is no added benefit of virtual modules. Even with virtual modules, the declarations need to be emitted. Emitting the declarations entails emitting a Closing this for now. Re-open if you disagree |
Feedback wanted for the new bundler config
experimentalUseVirtualModules
which has been released recently.allowJs: true
in their TypeScript config Generate TypeScript files instead of JS files? #238.gitignore
and.prettierignore
files (or offer option to disable generation) #189import { paraglide } from "@inlang/paraglide-sveltekit/vite" import { defineConfig } from "vite" export default defineConfig({ plugins: [ paraglide({ project: "./project.inlang", outdir: "./src/lib/paraglide", + experimentalUseVirtualModules: true, }), // ... other vite plugins ], })
The compiled output will only emit the
runtime.d.ts
andmessages.d.ts
files.The text was updated successfully, but these errors were encountered: