I am trying to build 6 different ReactJs bundles for 6 different languages.
As the first step I am trying to pass a custom --lang
argument to the vite build
command by adding the following 6 lines to the package.json of my project:
"scripts": {
"dev": "vite",
"build en": "vite build --lang=en",
"build de": "vite build --lang=de",
"build fr": "vite build --lang=fr",
"build nl": "vite build --lang=nl",
"build pl": "vite build --lang=pl",
"build ru": "vite build --lang=ru",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
Unfortunately, running any of the 6 new commands fails with:
> permanent-drawer@0.0.0 build de
> vite build --lang=de
file:///src/react-questions/permanent-drawer/node_modules/vite/dist/node/cli.js:444
throw new CACError(`Unknown option \`${name.length > 1 ? `--${name}` : `-${name}`}\``);
^
CACError: Unknown option `--lang`
at Command.checkUnknownOptions (file:///src/react-questions/permanent-drawer/node_modules/vite/dist/node/cli.js:444:17)
Here a VS Code screenshot showing the error:
Does anybody please have a suggestion for me, how to make vite accept new --lang
parameter?
My final target is to add a plugin which would take the lang parameter and use it to localize __placeholder__
strings in the generated bundle file. So that at the end I can have 6 localized bundles.
I have resolved my problem by adding "--" before the custom argument:
"scripts": {
"dev": "vite",
"build en": "vite build -- --lang=en",
"build de": "vite build -- --lang=de",
"build fr": "vite build -- --lang=fr",
"build nl": "vite build -- --lang=nl",
"build pl": "vite build -- --lang=pl",
"build ru": "vite build -- --lang=ru",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
Also, at the end I didn't need this custom --lang
parameter and have found a better way to have localized bundles generated as the result of the "vite build" command.