createConfig
1import { createConfig } from '@nx/angular-rsbuild';
2The createConfig function is used to create an Rsbuild configuration object setup for Angular applications.
It takes an optional RsbuildConfig object as an argument, which allows for customization of the Rsbuild configuration.
1async function createConfig(
2 defaultOptions: {
3 options: PluginAngularOptions;
4 rsbuildConfigOverrides?: Partial<RsbuildConfig>;
5 },
6 configurations: Record<
7 string,
8 {
9 options: Partial<PluginAngularOptions>;
10 rsbuildConfigOverrides?: Partial<RsbuildConfig>;
11 }
12 > = {},
13 configEnvVar = 'NGRS_CONFIG'
14);
15Examples
The following example shows how to create a configuration for a SSR application:
1import { createConfig } from '@nx/angular-rsbuild';
2
3export default createConfig({
4 options: {
5 browser: './src/main.ts',
6 server: './src/main.server.ts',
7 ssrEntry: './src/server.ts',
8 },
9});
10PluginAngularOptions
The PluginAngularOptions object is an object that contains the following properties:
1export interface PluginAngularOptions extends PluginUnsupportedOptions {
2 aot?: boolean;
3 assets?: AssetElement[];
4 browser?: string;
5 commonChunk?: boolean;
6 devServer?: DevServerOptions;
7 extractLicenses?: boolean;
8 fileReplacements?: FileReplacement[];
9 index?: IndexElement;
10 inlineStyleLanguage?: InlineStyleLanguage;
11 namedChunks?: boolean;
12 optimization?: boolean | OptimizationOptions;
13 outputHashing?: OutputHashing;
14 outputPath?:
15 | string
16 | (Required<Pick<OutputPath, 'base'>> & Partial<OutputPath>);
17 polyfills?: string[];
18 root?: string;
19 scripts?: ScriptOrStyleEntry[];
20 server?: string;
21 skipTypeChecking?: boolean;
22 sourceMap?: boolean | Partial<SourceMap>;
23 ssr?:
24 | boolean
25 | {
26 entry: string;
27 experimentalPlatform?: 'node' | 'neutral';
28 };
29 stylePreprocessorOptions?: StylePreprocessorOptions;
30 styles?: ScriptOrStyleEntry[];
31 tsConfig?: string;
32 useTsProjectReferences?: boolean;
33 vendorChunk?: boolean;
34}
35
36export interface DevServerOptions extends DevServerUnsupportedOptions {
37 port?: number;
38 ssl?: boolean;
39 sslKey?: string;
40 sslCert?: string;
41 proxyConfig?: string;
42}
43
44export interface OptimizationOptions {
45 scripts?: boolean;
46 styles?: boolean;
47 fonts?: boolean;
48}
49
50export type OutputHashing = 'none' | 'all' | 'media' | 'bundles';
51export type HashFormat = {
52 chunk: string;
53 extract: string;
54 file: string;
55 script: string;
56};
57
58export interface OutputPath {
59 base: string;
60 browser: string;
61 server: string;
62 media: string;
63}
64
65export type AssetExpandedDefinition = {
66 glob: string;
67 input: string;
68 ignore?: string[];
69 output?: string;
70};
71export type AssetElement = AssetExpandedDefinition | string;
72export type NormalizedAssetElement = AssetExpandedDefinition & {
73 output: string;
74};
75export type ScriptOrStyleEntry =
76 | string
77 | {
78 input: string;
79 bundleName?: string;
80 inject?: boolean;
81 };
82export type GlobalEntry = {
83 name: string;
84 files: string[];
85 initial: boolean;
86};
87export type IndexExpandedDefinition = {
88 input: string;
89 output?: string;
90 preloadInitial?: boolean;
91};
92export type IndexElement = IndexExpandedDefinition | string | false;
93export type IndexHtmlTransform = (content: string) => Promise<string>;
94export type NormalizedIndexElement =
95 | (IndexExpandedDefinition & {
96 insertionOrder: [string, boolean][];
97 transformer: IndexHtmlTransform | undefined;
98 })
99 | false;
100
101export interface SourceMap {
102 scripts: boolean;
103 styles: boolean;
104 hidden: boolean;
105 vendor: boolean;
106}
107
108export type InlineStyleExtension = 'css' | 'scss' | 'sass' | 'less';
109export interface FileReplacement {
110 replace: string;
111 with: string;
112}
113export interface StylePreprocessorOptions {
114 includePaths?: string[];
115 sass?: Sass;
116}
117export interface Sass {
118 fatalDeprecations?: DeprecationOrId[];
119 futureDeprecations?: DeprecationOrId[];
120 silenceDeprecations?: DeprecationOrId[];
121}
122aot
boolean default: true Enables or disables Ahead-of-Time compilation for Angular applications.
assets
AssetElement[] Array of static assets to include in the build output. Can be either a string path or an object with glob patterns.
browser
string The entry point file for the browser bundle (e.g., 'src/main.ts').
commonChunk
boolean default: true Controls whether to create a separate bundle containing shared code between multiple chunks.
devServer
DevServerOptions RsbuildConfig options for the development server including port, SSL settings, and proxy configuration.
extractLicenses
boolean default: false When true, extracts all license information from dependencies into a separate file.
fileReplacements
FileReplacement[] List of files to be replaced during the build process, typically used for environment-specific configurations.
index
IndexElement Configuration for the index.html file. Can be a string path, an object with specific settings, or false to disable.
inlineStyleLanguage
InlineStyleLanguage Specifies the default language to use for inline styles in components.
namedChunks
boolean default: true When true, generates named chunks instead of numerical IDs.
optimization
boolean | OptimizationOptions default: true Controls build optimization settings for scripts, styles, and fonts.
outputHashing
OutputHashing default: 'none' Defines the hashing strategy for output files. Can be 'none', 'all', 'media', or 'bundles'.
outputPath
string | OutputPath Specifies the output directory for built files. Can be a string or an object defining paths for browser, server, and media files.
polyfills
string[] Array of polyfill files to include in the build.
root
string The root directory of the project where the rsbuild.config.ts file is located.
scripts
ScriptOrStyleEntry[] Array of global scripts to include in the build, with options for bundling and injection.
server
string The entry point file for the server bundle in SSR applications.
skipTypeChecking
boolean default: false When true, skips TypeScript type checking during the build process.
sourceMap
boolean | Partial<SourceMap> default: true Controls generation of source maps for debugging. Can be boolean or detailed configuration object.
ssr
boolean | { entry: string; experimentalPlatform?: 'node' | 'neutral' } Configuration for Server-Side Rendering. Can be boolean or object with specific SSR settings.
stylePreprocessorOptions
StylePreprocessorOptions Options for style preprocessors, including include paths and Sass-specific configurations.
styles
ScriptOrStyleEntry[] Array of global styles to include in the build, with options for bundling and injection.
tsConfig
string Path to the TypeScript configuration file.
useTsProjectReferences
boolean default: false Enables usage of TypeScript project references.
vendorChunk
boolean default: true When true, creates a separate bundle for vendor (third-party) code.