-
Hello dear Vite users and developers! I have prepared a minimal test project at Github to demonstrate, what I have already tried myself: My goal is to generate one bundle per supported language. In other words, I do not want let users to switch languages at the runtime in my React app, because my real app is pretty large and country-specific. Instead I would like to generate these 3 files and then serve them from different URLs at my backend:
So I have tried to create my custom Vite plugin vite-plugin-react-localize.js which replaces
To activate the plugin I have added it to the vite-config.js:
And finally, I have added the 3 build commands to the package.json:
My approach kind of works now and the nice thing is that even the "dev" task preview is properly localized to the default "en" language. Here a screenshot of my VS Code: However I have not achieved the goal of being able to generate 3 different dist/index-*.js files. And I have a feeling, that there must be a better way to approach this problem. Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Ok, solved my problem by utilizing the generateBundle hook: Here my custom vite-plugin-react-localize.js file:
It is called with the help of the modified vite.config.js file:
Now the "vite build" works as I wanted and produces 3 additional files: |
Beta Was this translation helpful? Give feedback.
Ok, solved my problem by utilizing the generateBundle hook:
Here my custom vite-plugin-react-localize.js file: