The goal of @ng-rsbuild/plugin-angular
and @ng-rspack/build
is to make it easy and straightforward to build Angular applications with Rspack and Rsbuild.
The following aims to compare features of Rspack and Rsbuild, and it's Angular wrapper with Angular's standards (Angular CLI and Webpack/esbuild).
Rspack and Rsbuild are modern, high-performance JavaScript build tools designed as alternatives to Webpack and other traditional bundlers.
This table maps the key ng-rspack
and ng-rsbuild
packages to their equivalent Angular CLI components to show how Rspack and Rsbuild replace or mirror Angular CLI's system.
ng-rspack / ng-rsbuild Package | New Equivalent in Angular CLI / DevKit | Old Equivalent in Angular CLI / DevKit | Description |
---|---|---|---|
@ng-rspack/build | @angular/build | @angular-devkit/build-angular | Core build system for ng-rspack, replacing Angular CLI's Webpack-based builder. |
@ng-rspack/compiler | @angular/build | @angular/build | Compiler for Angular applications using Rspack, leveraging abstractions from @angular/build . |
@ng-rspack/nx | n/a (@nx/angular as already 3rd party) | n/a (@nx/angular as already 3rd party) | Provides Nx integration for RsPack and RsBuild in Angular, like @nx/angular for Angular CLI. |
@ng-rsbuild/plugin-angular | @angular/build (Builder API) | @angular-devkit/build-angular | Rsbuild plugin for Angular projects, similar to Angular CLI's Webpack-based builder API. |
@ng-rsbuild/plugin-nx | @nx/angular | @nx/angular | Provides Nx integration for RsPack and RsBuild in Angular, like @nx/angular for Angular CLI. |
Legend:
- β Fully Supported
β οΈ Partial Support- β Not Supported
- π Not Applicable
- π Best-in-Class
Feature | State | ng-rspack / ng-rsbuild Package | State | New Equivalent (@angular/build) | State | Old Equivalent (@angular-devkit) | Notes |
---|---|---|---|---|---|---|---|
Builder / Build Performance | β π | [1] Rspack / Rsbuild | β | Angular Esbuild | Webpack | Rspack & Rsbuild (Rust-based) are optimized for performance. New Angular uses Esbuild, replacing Webpack for faster builds. | |
Plugins & Loaders | β | - | β | - | β | - | |
- CSS Loader | β | CSS Loader | β | CSS Loader | β | CSS Loader | |
- SCSS/SASS Loader | β | SCSS Loader | β | SCSS Loader | β | SCSS Loader | |
- LESS Loader | β | LESS Loader | β | LESS Loader | β | LESS Loader | |
- Style Loader | π§ | Style Loader | β | Style Loader | β | Style Loader | |
Configuration File (Bundler) | β | Rspack Config (rspack.config.js ) |
β | Angular JSON (angular.json ) |
β | Webpack Config (webpack.config.js ) |
Angular combines bundler and builder configs in one file (angular.json ) |
Configuration File (Builder) | β | Rsbuild Config (rsbuild.config.ts ) |
β | Angular JSON (angular.json ) |
β | Webpack Config (webpack.config.js ) |
|
Compiler | β | @ng-rspack/compiler | β | @angular/build | β | @angular/compiler | |
Automatic Downleveling via browserslist |
β | - | β | - | β | - | Can be supported via Rspack Target |
Build Flags (NG_BUILD_MANGLE=0 , etc.) |
β | - | β | - | β | - | No method to override SWC options |
HMR (Hot Module Replacement) | @ng-rspack/build @ng-rsbuild/plugin-angular | β | @angular/build | β | @angular-devkit/build-angular | ||
TypeScript Handling | β | Rspack SWC | β | Angular Esbuild | β | Webpack TypeScript | Rspack uses SWC, Angular uses Esbuild |
Tree Shaking | β | - | β | - | β | - | |
Asset Management | β | - | β | - | β | - | |
Development Server | β | - | β | - | β | - | |
Schematics | - | β | - | β | - | ||
- Generate Application | - | β | ng generate app |
β | ng generate app |
||
- Serve Application | β | - | β | ng serve |
β | ng serve |
|
- Build Application | β | - | β | ng build |
β | ng build |
|
Nx Plugin | β | @ng-rspack/plugin-nx | π | @nx/angular | π | @nx/angular | Nx is a 3rd party |
Nx Integration | β | @ng-rspack/nx | π | n/a | π | n/a | Already 3rd party (@nx/angular ) |
Migration from Webpack | β | - | - | - | Rspack serves as a drop-in replacement for Webpack; Angular is transitioning to Esbuild |
- [1] For build speed comparison see benchmarks
Configuration is controlled entirely via the Rspack/Rsbuild config.
Both tools offer a createConfig
function to aid in the creation of the configuration.
The documentation for this project can be found at angular-rspack.dev.
Thank you to Brandon Roberts and Analog for their work on building Angular applications with Vite which both inspired this plugin and provided a basis for the compilation implementation.
Currently, the Rsbuild support is more feature complete than the Rspack support.
There exists an Rsbuild plugin that can be used with a rsbuild.config.ts
file to support compiling Angular applications with Rsbuild.
Prerequisites: Angular SSR Application already created with ng new --ssr
.
- Install Rsbuild:
npm install --save-dev @rsbuild/core
- Install this plugin:
npm install --save-dev @ng-rsbuild/plugin-angular
- Create an
rsbuild.config.ts
file at the root of your project with the following:
import { createConfig } from '@ng-rsbuild/plugin-angular';
export default createConfig({
browser: './src/main.ts',
server: './src/main.server.ts',
ssrEntry: './src/server.ts',
});
- Update your
./src/server.ts
file to use thecreateServer
util:
import { createServer } from '@ng-rsbuild/plugin-angular/ssr';
import bootstrap from './main.server';
const server = createServer(bootstrap);
/** Add your custom server logic here
*
* For example, you can add a custom static file server:
*
* server.app.use('/static', express.static(staticFolder));
*
* Or add additional api routes:
*
* server.app.get('/api/hello', (req, res) => {
* res.send('Hello World!');
* });
*
* Or add additional middleware:
*
* server.app.use((req, res, next) => {
* res.send('Hello World!');
* });
*/
server.listen();
- Run the builds:
npx rsbuild build
- Run the server:
node dist/server/server.js
- Run the dev server:
npx rsbuild dev
Prerequisites: Angular CSR Application already created with ng new
.
- Install Rsbuild:
npm install --save-dev @rsbuild/core
- Install this plugin:
npm install --save-dev @ng-rsbuild/plugin-angular
- Create an
rsbuild.config.ts
file at the root of your project with the following:
import { createConfig } from '@ng-rsbuild/plugin-angular';
export default createConfig({
browser: './src/main.ts',
});
- Run the builds:
npx rsbuild build
- Run the dev server:
npx rsbuild dev
Currently, this is still being viewed as a proof-of-concept.
There needs to be a lot more comprehensive testing before this is viable for real applications.
The current objective is to get HMR working correctly.
Right now, the state of it is as follows:
- The global
ng
module is missing, causing warnings when HMR updates are applied. - Only changes to the following cause an HMR update:
- Global Styles
- Inline Templates
- TS portion of Components
- The following need support (non-exhaustive):
- Inline Styles
- Template Files
- Component Style Files
# Create a new nx workspace
npx create-nx-workspace ng-rspack-test
# Choose options:
# - Stack: None
# - Integrated Monorepo
# - CI: Do it later
# - Remote caching: Up to you
# Change into project directory and install the ng-rspack-build package
cd ng-rspack-test
npm install @ng-rspack/nx
# Run the app generator
npx nx g @ng-rspack/nx:app apps/myapp
# Choose stylesheet format and e2e framework
# Serve the app
npx nx serve myapp
# Build the app
npx nx build myapp
# Run the e2e tests
npx nx e2e myapp-e2e