Handling Configurations
Configurations are handled slightly differently compared to the Angular CLI. Rsbuild and Rspack use mode
instead of configurations to handle different environments by default. This means that a different solution is needed to handle different build configurations you may have to match the behavior of Angular's configuration handling.
The createConfig
function helps you to handle this. It uses the NGRS_CONFIG
environment variable to determine which configuration to use. The default configuration is production
.
You can handle configurations by yourself if you prefer, all you need is some manner of detecting the environment and then merging the options passed to createConfig
.
Using createConfig
for configurations
The createConfig
function takes two arguments, the first is the default options, and the second is an object of configurations. The configurations object is keyed by the name of the configuration, and the value is an object with the options and rspackConfigOverrides | rsbuildConfigOverrides
to be used for that configuration.
1import { createConfig } from '@nx/angular-rspack';
2export default createConfig(
3 {
4 options: {
5 browser: './src/main.ts',
6 server: './src/main.server.ts',
7 ssrEntry: './src/server.ts',
8 },
9 rspackConfigOverrides: {
10 mode: 'development',
11 },
12 },
13 {
14 production: {
15 options: {
16 fileReplacements: [
17 {
18 replace: './src/environments/environment.ts',
19 with: './src/environments/environment.prod.ts',
20 },
21 ],
22 },
23 },
24 }
25);
26
The above example shows how to handle the production
configuration. The options
are the same as the default options but with the fileReplacements
property added, and the rspackConfigOverrides
are the same as the default rspackConfigOverrides
.
The NGRS_CONFIG
environment variable is used to determine which configuration to use. If the environment variable is not set, the production
configuration is used by default. If a production configuration is not provided, the default configuration is used.
To run the build with the production
configuration:
1NGRS_CONFIG=production npx myapp build
2