<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> The docs specify that the react library generator supports using rspack as a bundler option. The react library generator does not have rspack as an option. ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> Remove misleading docs ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
3.2 KiB
| title | description |
|---|---|
| Overview of the Nx Rspack Plugin | The Nx Plugin for Rspack contains executors, generators, and utilities for managing Rspack projects in an Nx Workspace. |
The Nx Plugin for Rspack contains executors, generators, and utilities for managing Rspack projects in an Nx Workspace.
Setting Up @nx/rspack
Installation
{% callout type="note" title="Keep Nx Package Versions In Sync" %}
Make sure to install the @nx/rspack version that matches the version of nx in your repository. If the version numbers get out of sync, you can encounter some difficult to debug errors. You can fix Nx version mismatches with this recipe.
{% /callout %}
In any Nx workspace, you can install @nx/rspack by running the following command:
{% tabs %} {% tab label="Nx 18+" %}
nx add @nx/rspack
This will install the correct version of @nx/rspack.
How @nx/rspack Infers Tasks
The @nx/rspack plugin will create a task for any project that has a Rspack configuration file present. Any of the following files will be recognized as a Rspack configuration file:
rspack.config.jsrspack.config.tsrspack.config.mjsrspack.config.mtsrspack.config.cjsrspack.config.cts
View Inferred Tasks
To view inferred tasks for a project, open the project details view in Nx Console or run nx show project my-project --web in the command line.
@nx/rspack Configuration
The @nx/rspack/plugin is configured in the plugins array in nx.json.
{
"plugins": [
{
"plugin": "@nx/rspack/plugin",
"options": {
"buildTargetName": "build",
"previewTargetName": "preview",
"serveTargetName": "serve",
"serveStaticTargetName": "serve-static"
}
}
]
}
The buildTargetName, previewTargetName, serveTargetName and serveStaticTargetName options control the names of the inferred Rspack tasks. The default names are build, preview, serve and serve-static.
{% /tab %} {% tab label="Nx < 18" %}
Install the @nx/rspack package with your package manager.
npm add -D @nx/rspack
{% /tab %} {% /tabs %}
Using @nx/rspack
Generate a new project using Rspack
You can generate a React application that uses Rspack. The @nx/react:app generator accepts the bundler option, where you can pass rspack. This will generate a new application configured to use Rspack, and it will also install all the necessary dependencies, including the @nx/rspack plugin.
To generate a React application using Rspack, run the following:
nx g @nx/react:app my-app --bundler=rspack
Modify an existing React project to use Rspack
You can use the @nx/rspack:configuration generator to change your React to use Rspack. This generator will modify your project's configuration to use Rspack, and it will also install all the necessary dependencies, including the @nx/rspack plugin.
You can read more about this generator on the @nx/rspack:configuration generator page.