Registry / devops / vite-plugin-laravel-translations

vite-plugin-laravel-translations

JSON →
library0.3.1jsnpmunverified

Vite plugin that retrieves Laravel PHP translation files and makes them available as a global JSON variable (`import.meta.env.VITE_LARAVEL_TRANSLATIONS`) for use with i18n frameworks like vue-i18n or react-i18next. Version 0.3.1 supports Vite 3–6 and Node >=12. It uses Vite-specific hooks (`config`, `handleHotUpdate`) and cannot be used as a Rollup plugin. Key differentiators: automatic PHP-to-JSON conversion, HMR support for translation files, and optional namespacing for React compatibility. Alternative to manual JSON generation or PHP-based solutions like `laravel-vue-i18n`.

npm install vite-plugin-laravel-translations
INSTALL
IMPORT
SIG · VITE-PLUGIN-LARAVE
V
vite-plugin-laravel-translations
devopsjavascriptv0.3.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (plugin)
✓ import laravelTranslations from 'vite-plugin-laravel-translations'
✗ const laravelTranslations = require('vite-plugin-laravel-translations')
The package is ESM-only; CommonJS require() will fail. Use default import.
dynamic import (v0.1.5+)
✓ const laravelTranslations = (await import('vite-plugin-laravel-translations')).default
✗ const laravelTranslations = await import('vite-plugin-laravel-translations')
When using dynamic import, you must access .default because the module exports default.
import.meta.env.VITE_LARAVEL_TRANSLATIONS
✓ const messages = import.meta.env.VITE_LARAVEL_TRANSLATIONS
✗ const messages = process.env.VITE_LARAVEL_TRANSLATIONS
This is a Vite env variable injected at build time, not a Node.js environment variable. Use import.meta.env.

Shows basic Vite plugin setup and Vue 3 i18n integration using the injected env variable.

// vite.config.js import { defineConfig } from 'vite'; import laravelTranslations from 'vite-plugin-laravel-translations'; export default defineConfig({ plugins: [ laravelTranslations({ // Include Laravel JSON translation files (e.g., resources/lang/vendor/*.json) includeJson: false, // Namespace for React i18next compatibility (e.g., 'translation') namespace: false, }), ], }); // resources/js/app.js (Vue 3 example) import { createApp } from 'vue'; import { createI18n } from 'vue-i18n'; const i18n = createI18n({ locale: 'en', fallbackLocale: 'en', messages: import.meta.env.VITE_LARAVEL_TRANSLATIONS, }); const app = createApp({}); app.use(i18n); app.mount('#app');
Debug
Known issues
breakingPlugin uses Vite-specific hooks (config & handleHotUpdate) and cannot be used as a Rollup plugin.
fix
Use only with Vite. Do not attempt to use with Rollup or other bundlers.
affects: >=0.0.1-rc.1
gotchaThe injected variable is `import.meta.env.VITE_LARAVEL_TRANSLATIONS`, not `process.env.VITE_LARAVEL_TRANSLATIONS`.
fix
Always use import.meta.env in your application code.
affects: >=0.0.1-rc.1
gotchaDynamic import in v0.1.5+ requires accessing .default after await import().
fix
Use `const laravelTranslations = (await import('vite-plugin-laravel-translations')).default`
affects: >=0.1.5
deprecatedThe `includeJson` option is marked as 'TBC' (To Be Confirmed) in the README - behavior may change.
fix
Set `includeJson: false` explicitly until future clarification.
affects: <=0.3.1
gotchaPlugin indexes PHP files from `resources/lang/` by default. Ensure your Laravel structure matches.
fix
Verify translations are in `resources/lang/{locale}/` or adjust as needed; custom paths not documented.
affects: >=0.0.1-rc.1
breakingPeer dependency vite is required; install failures may occur if version outside ^3.2.11 || ^4.0.0 || ^5.1.3 || ^6.0.
fix
Install a compatible vite version (e.g., npm i vite@^5.1.3).
affects: >=0.2.2
Errors
Common errors & fixes
require() of ES Module /path/to/node_modules/vite-plugin-laravel-translations/index.js not supported.
Package is ESM-only; CommonJS require() fails.
fix
Use ES import syntax: `import laravelTranslations from 'vite-plugin-laravel-translations'`
VITE_LARAVEL_TRANSLATIONS is not defined / undefined
The env variable is only available after the plugin runs; if accessed before plugin execution or in plain Node scripts.
fix
Ensure the plugin is added to the Vite config and access `import.meta.env.VITE_LARAVEL_TRANSLATIONS` inside your app (not in vite.config.js).
Cannot find module 'vite-plugin-laravel-translations'
Package not installed or mismatched peer dependency (vite version).
fix
Run `npm i vite-plugin-laravel-translations` and ensure vite peer dependency is satisfied.
Uncaught TypeError: laravelTranslations is not a function
Default import not used correctly (e.g., `import * as laravelTranslations`).
fix
Use default import: `import laravelTranslations from 'vite-plugin-laravel-translations'`
Upgrade
Version history
0.3.1latest on npm
Audit
Dependencies
viterequiredPeer dependency; plugin uses Vite-specific hooks and is incompatible with Rollup.
Agent activity
32 hits · last 30 days
node
30
OpenAI (training)
1
Resources
vite-plugin-laravel-translations — npm install vite-plugin-laravel-translations · libregistry