@nx/vite:configuration
Configure a project to use Vite.js.
Monorepo World: October 7, 2024Monorepo World: October 7, 2024Join us!
Configure a project to use Vite.js.
This generator is used for converting an existing React or Web project to use Vite.js.
It will create a vite.config.ts
file at the root of your project with the correct settings, or if there's already a vite.config.ts
file, it will modify it to include the correct settings.
This generator will modify your code, so make sure to commit your changes before running it.
1nx g @nx/vite:configuration
2
When running this generator, you will be prompted to provide the following:
project
, as the name of the project you want to generate the configuration for.uiFramework
you want to use. Supported values are: react
and none
.You must provide a project
and a uiFramework
for the generator to work.
You may also pass the includeVitest
flag. This will also configure your project for testing with Vitest, by adding the test
configuration in your vite.config.ts
file.
If you have an existing project that does not use Vite, you may want to convert it to use Vite. This can be a webpack
project, a buildable JS library that uses the @nx/js:babel
, the @nx/js:swc
or the @nx/rollup:rollup
executor, or even a non-buildable library. By default, the @nx/vite:configuration
generator will search your project to find the relevant configuration (either a webpack.config.ts
file for example, or the @nx/js
executors). If it determines that your project can be converted, then Nx will generate the configuration for you. If it cannot determine that your project can be converted, it will ask you if you want to convert it anyway or throw an error if it determines that it cannot be converted.
You can then test on your own if the result works or not, and modify the configuration as needed. It's suggested that you commit your changes before running the generator, so you can revert the changes if needed.
@nx/vite
executorsUsually, React and Web projects generated with the @nx/react
and the @nx/web
generators can be converted to use the @nx/vite
executors without any issues.
The list of executors for building, testing and serving that can be converted to use the @nx/vite
executors is:
build
executors@nxext/vite:build
@nx/js:babel
@nx/js:swc
@nx/rollup:rollup
@nx/webpack:webpack
@nx/web:rollup
@nx/angular:ng-packagr-lite
@nx/angular:package
@nx/angular:webpack-browser
@angular-devkit/build-angular:browser
@angular-devkit/build-angular:dev-server
@nx/esbuild:esbuild
@nx/react-native:start
@nx/next:build
@nx/next:server
@nx/js:tsc
We cannot guarantee that projects using unsupported executors - or any executor that is NOT listed in the list of "supported executors" - for either building, testing or serving will work correctly when converted to use Vite.
You can read more in the Vite package overview page.
1nx g @nx/vite:configuration --project=my-react-app --uiFramework=react --includeVitest
2
This will configure the my-react-app
project to use Vite.
1nx g @nx/vite:configuration --project=my-web-app --uiFramework=none --includeVitest
2
This will configure the my-web-app
project to use Vite.
1nx generate configuration ...
2
1nx g config ... #same
2
By default, Nx will search for configuration
in the default collection provisioned in workspace.json.
You can specify the collection explicitly as follows:
1nx g @nx/vite:configuration ...
2
Show what will be generated without writing to disk:
1nx g configuration ... --dry-run
2
babel
babel
, swc
Compiler to use for Vite when UI Framework is React.
Add a library build option and skip the server option.
Use vitest for the test suite.
false
Is this a new project?
The name of the project.
jsdom
node
, jsdom
, happy-dom
, edge-runtime
The vitest environment to use. See https://vitest.dev/config/#environment.
none
react
, none
UI Framework to use for Vite.
false
Skip formatting files.
Join us live for exciting talks on developer tooling and monorepos! Catch the action on YouTube and join the conversation on Discord!