@nx/angular-rspack 19.0.0-alpha.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/code-pushup.config.ts +13 -0
  4. package/dist/lib/config/create-config.d.ts +11 -0
  5. package/dist/lib/config/create-config.d.ts.map +1 -0
  6. package/dist/lib/config/create-config.js +417 -0
  7. package/dist/lib/config/dev-server-config-utils.d.ts +3 -0
  8. package/dist/lib/config/dev-server-config-utils.d.ts.map +1 -0
  9. package/dist/lib/config/dev-server-config-utils.js +101 -0
  10. package/dist/lib/config/helpers.d.ts +3 -0
  11. package/dist/lib/config/helpers.d.ts.map +1 -0
  12. package/dist/lib/config/helpers.js +37 -0
  13. package/dist/lib/config/style-config-utils.d.ts +261 -0
  14. package/dist/lib/config/style-config-utils.d.ts.map +1 -0
  15. package/dist/lib/config/style-config-utils.js +62 -0
  16. package/dist/lib/index.d.ts +3 -0
  17. package/dist/lib/index.d.ts.map +1 -0
  18. package/dist/lib/index.js +5 -0
  19. package/dist/lib/models/angular-rspack-plugin-options.d.ts +114 -0
  20. package/dist/lib/models/angular-rspack-plugin-options.d.ts.map +1 -0
  21. package/dist/lib/models/angular-rspack-plugin-options.js +2 -0
  22. package/dist/lib/models/augmented-compilation.d.ts +11 -0
  23. package/dist/lib/models/augmented-compilation.d.ts.map +1 -0
  24. package/dist/lib/models/augmented-compilation.js +4 -0
  25. package/dist/lib/models/index.d.ts +4 -0
  26. package/dist/lib/models/index.d.ts.map +1 -0
  27. package/dist/lib/models/index.js +6 -0
  28. package/dist/lib/models/normalize-options.d.ts +16 -0
  29. package/dist/lib/models/normalize-options.d.ts.map +1 -0
  30. package/dist/lib/models/normalize-options.js +362 -0
  31. package/dist/lib/plugins/angular-rspack-plugin.d.ts +9 -0
  32. package/dist/lib/plugins/angular-rspack-plugin.d.ts.map +1 -0
  33. package/dist/lib/plugins/angular-rspack-plugin.js +148 -0
  34. package/dist/lib/plugins/angular-ssr-dev-server.d.ts +8 -0
  35. package/dist/lib/plugins/angular-ssr-dev-server.d.ts.map +1 -0
  36. package/dist/lib/plugins/angular-ssr-dev-server.js +49 -0
  37. package/dist/lib/plugins/client/ssr-reload-client.d.ts +2 -0
  38. package/dist/lib/plugins/client/ssr-reload-client.d.ts.map +1 -0
  39. package/dist/lib/plugins/client/ssr-reload-client.js +16 -0
  40. package/dist/lib/plugins/loaders/angular-partial-transform.loader.d.ts +3 -0
  41. package/dist/lib/plugins/loaders/angular-partial-transform.loader.d.ts.map +1 -0
  42. package/dist/lib/plugins/loaders/angular-partial-transform.loader.js +36 -0
  43. package/dist/lib/plugins/loaders/angular-transform.loader.d.ts +3 -0
  44. package/dist/lib/plugins/loaders/angular-transform.loader.d.ts.map +1 -0
  45. package/dist/lib/plugins/loaders/angular-transform.loader.js +39 -0
  46. package/dist/lib/plugins/ng-rspack.d.ts +8 -0
  47. package/dist/lib/plugins/ng-rspack.d.ts.map +1 -0
  48. package/dist/lib/plugins/ng-rspack.js +114 -0
  49. package/dist/lib/plugins/rxjs-esm-resolution.d.ts +5 -0
  50. package/dist/lib/plugins/rxjs-esm-resolution.d.ts.map +1 -0
  51. package/dist/lib/plugins/rxjs-esm-resolution.js +15 -0
  52. package/dist/lib/plugins/server/ssr-reload-server.d.ts +6 -0
  53. package/dist/lib/plugins/server/ssr-reload-server.d.ts.map +1 -0
  54. package/dist/lib/plugins/server/ssr-reload-server.js +18 -0
  55. package/dist/lib/plugins/tools/dev-tools-ignore-plugin.d.ts +17 -0
  56. package/dist/lib/plugins/tools/dev-tools-ignore-plugin.d.ts.map +1 -0
  57. package/dist/lib/plugins/tools/dev-tools-ignore-plugin.js +57 -0
  58. package/dist/lib/ssr/server.d.ts +13 -0
  59. package/dist/lib/ssr/server.d.ts.map +1 -0
  60. package/dist/lib/ssr/server.js +47 -0
  61. package/eslint.next.config.js +42 -0
  62. package/package.json +83 -0
  63. package/vitest.config.mts +21 -0
  64. package/vitest.integration.config.mts +28 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Colum Ferry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ <div style="text-align: center;">
2
+
3
+ # @nx/angular-rspack
4
+
5
+ [![GitHub Actions](https://github.com/nrwl/angular-rspack/actions/workflows/ci.yml/badge.svg)](https://github.com/nrwl/angular-rspack/actions/workflows/ci.yml)
6
+ ![License](https://img.shields.io/badge/License-MIT-blue)
7
+ [![NPM Version](https://img.shields.io/npm/v/%40ng-rspack%2Fbuild?label=%40nx%2Fangular-rspack)](https://www.npmjs.com/package/@ng-rspack/build)
8
+
9
+ </div>
10
+
11
+ <hr>
12
+
13
+ # Build Angular with Rspack
14
+
15
+ The goal of `@nx/angular-rspack` is to make easy and straightforward to build Angular applications with [rspack](https://rspack.dev).
@@ -0,0 +1,13 @@
1
+ import { CoreConfig } from '@code-pushup/models';
2
+ import { mergeConfigs } from '@code-pushup/utils';
3
+ import {
4
+ baseConfig,
5
+ coverageCoreConfig,
6
+ eslintConfig,
7
+ } from '../../tools/reports/code-pushup.preset.config';
8
+
9
+ export default mergeConfigs(
10
+ baseConfig as CoreConfig,
11
+ await eslintConfig(),
12
+ await coverageCoreConfig()
13
+ );
@@ -0,0 +1,11 @@
1
+ import { Configuration } from '@rspack/core';
2
+ import { AngularRspackPluginOptions } from '../models';
3
+ export declare function _createConfig(options: AngularRspackPluginOptions, rspackConfigOverrides?: Partial<Configuration>): Promise<Configuration[]>;
4
+ export declare function createConfig(defaultOptions: {
5
+ options: AngularRspackPluginOptions;
6
+ rspackConfigOverrides?: Partial<Configuration>;
7
+ }, configurations?: Record<string, {
8
+ options: Partial<AngularRspackPluginOptions>;
9
+ rspackConfigOverrides?: Partial<Configuration>;
10
+ }>, configEnvVar?: string): Promise<Configuration[]>;
11
+ //# sourceMappingURL=create-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-config.d.ts","sourceRoot":"","sources":["../../../src/lib/config/create-config.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EAMd,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,0BAA0B,EAG3B,MAAM,WAAW,CAAC;AAkEnB,wBAAsB,aAAa,CACjC,OAAO,EAAE,0BAA0B,EACnC,qBAAqB,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAC7C,OAAO,CAAC,aAAa,EAAE,CAAC,CAkX1B;AAED,wBAAsB,YAAY,CAChC,cAAc,EAAE;IACd,OAAO,EAAE,0BAA0B,CAAC;IACpC,qBAAqB,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CAChD,EACD,cAAc,GAAE,MAAM,CACpB,MAAM,EACN;IACE,OAAO,EAAE,OAAO,CAAC,0BAA0B,CAAC,CAAC;IAC7C,qBAAqB,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;CAChD,CACG,EACN,YAAY,SAAgB,GAC3B,OAAO,CAAC,aAAa,EAAE,CAAC,CAyB1B"}
@@ -0,0 +1,417 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._createConfig = _createConfig;
4
+ exports.createConfig = createConfig;
5
+ const ng_rspack_1 = require("../plugins/ng-rspack");
6
+ const core_1 = require("@rspack/core");
7
+ const webpack_merge_1 = require("webpack-merge");
8
+ const path_1 = require("path");
9
+ const models_1 = require("../models");
10
+ const angular_rspack_compiler_1 = require("@nx/angular-rspack-compiler");
11
+ const style_config_utils_1 = require("./style-config-utils");
12
+ const helpers_1 = require("./helpers");
13
+ const dev_server_config_utils_1 = require("./dev-server-config-utils");
14
+ const dev_tools_ignore_plugin_1 = require("../plugins/tools/dev-tools-ignore-plugin");
15
+ function configureSourceMap(sourceMap) {
16
+ const { scripts, styles, hidden, vendor } = sourceMap;
17
+ const sourceMapRules = [];
18
+ const sourceMapPlugins = [];
19
+ if (scripts || styles) {
20
+ const include = [];
21
+ if (scripts) {
22
+ include.push(/js$/);
23
+ }
24
+ if (styles) {
25
+ include.push(/css$/);
26
+ }
27
+ sourceMapPlugins.push(new dev_tools_ignore_plugin_1.DevToolsIgnorePlugin());
28
+ sourceMapPlugins.push(new core_1.SourceMapDevToolPlugin({
29
+ filename: '[file].map',
30
+ include,
31
+ // We want to set sourceRoot to `webpack:///` for non
32
+ // inline sourcemaps as otherwise paths to sourcemaps will be broken in browser
33
+ // `webpack:///` is needed for Visual Studio breakpoints to work properly as currently
34
+ // there is no way to set the 'webRoot'
35
+ sourceRoot: 'webpack:///',
36
+ moduleFilenameTemplate: '[resource-path]',
37
+ append: hidden ? false : undefined,
38
+ }));
39
+ sourceMapRules.push({
40
+ test: /\.[cm]?jsx?$/,
41
+ enforce: 'pre',
42
+ loader: require.resolve('source-map-loader'),
43
+ options: {
44
+ filterSourceMappingUrl: (_mapUri, resourcePath) => {
45
+ if (vendor) {
46
+ // Consume all sourcemaps when vendor option is enabled.
47
+ return true;
48
+ }
49
+ // Don't consume sourcemaps in node_modules when vendor is disabled.
50
+ // But, do consume local libraries sourcemaps.
51
+ return !resourcePath.includes('node_modules');
52
+ },
53
+ },
54
+ });
55
+ }
56
+ return { sourceMapRules, sourceMapPlugins };
57
+ }
58
+ const VENDORS_TEST = /[\\/]node_modules[\\/]/;
59
+ async function _createConfig(options, rspackConfigOverrides) {
60
+ const normalizedOptions = (0, models_1.normalizeOptions)(options);
61
+ const isProduction = process.env['NODE_ENV'] === 'production';
62
+ const isDevServer = process.env['WEBPACK_SERVE'];
63
+ const hashFormat = (0, helpers_1.getOutputHashFormat)(normalizedOptions.outputHashing);
64
+ const { root } = normalizedOptions;
65
+ const { sourceMapRules, sourceMapPlugins } = configureSourceMap(normalizedOptions.sourceMap);
66
+ const defaultConfig = {
67
+ context: root,
68
+ mode: isProduction ? 'production' : 'development',
69
+ devtool: normalizedOptions.sourceMap.scripts ? 'source-map' : undefined,
70
+ output: {
71
+ uniqueName: 'rspack-angular',
72
+ publicPath: 'auto',
73
+ clean: true,
74
+ crossOriginLoading: false,
75
+ trustedTypes: { policyName: 'angular#bundler' },
76
+ sourceMapFilename: normalizedOptions.sourceMap.scripts
77
+ ? '[file].map'
78
+ : undefined,
79
+ },
80
+ resolve: {
81
+ extensions: ['.ts', '.tsx', '.mjs', '.js'],
82
+ modules: ['node_modules'],
83
+ mainFields: ['es2020', 'es2015', 'browser', 'module', 'main'],
84
+ conditionNames: ['es2020', 'es2015', '...'],
85
+ tsConfig: {
86
+ configFile: normalizedOptions.tsConfig,
87
+ },
88
+ },
89
+ experiments: {
90
+ css: true,
91
+ },
92
+ module: {
93
+ parser: {
94
+ javascript: {
95
+ requireContext: false,
96
+ url: false,
97
+ },
98
+ 'css/auto': {
99
+ esModule: true,
100
+ },
101
+ },
102
+ rules: [
103
+ ...(0, style_config_utils_1.getStyleLoaders)(normalizedOptions.stylePreprocessorOptions, normalizedOptions.sourceMap),
104
+ ...sourceMapRules,
105
+ { test: /[/\\]rxjs[/\\]add[/\\].+\.js$/, sideEffects: true },
106
+ {
107
+ test: angular_rspack_compiler_1.TS_ALL_EXT_REGEX,
108
+ use: [
109
+ {
110
+ loader: 'builtin:swc-loader',
111
+ options: {
112
+ jsc: {
113
+ parser: {
114
+ syntax: 'typescript',
115
+ },
116
+ target: 'es2022',
117
+ },
118
+ },
119
+ },
120
+ {
121
+ loader: require.resolve('@nx/angular-rspack/loaders/angular-loader'),
122
+ },
123
+ ],
124
+ },
125
+ {
126
+ test: angular_rspack_compiler_1.JS_ALL_EXT_REGEX,
127
+ use: [
128
+ {
129
+ loader: require.resolve('@nx/angular-rspack/loaders/angular-partial-transform-loader'),
130
+ },
131
+ ],
132
+ },
133
+ ],
134
+ },
135
+ plugins: [...sourceMapPlugins],
136
+ };
137
+ const configs = [];
138
+ if (normalizedOptions.hasServer) {
139
+ const serverConfig = {
140
+ ...defaultConfig,
141
+ name: 'server',
142
+ target: 'node',
143
+ entry: {
144
+ server: {
145
+ import: [normalizedOptions.ssr.entry],
146
+ },
147
+ },
148
+ output: {
149
+ ...defaultConfig.output,
150
+ publicPath: 'auto',
151
+ clean: true,
152
+ path: normalizedOptions.outputPath.server,
153
+ filename: '[name].js',
154
+ chunkFilename: '[name].js',
155
+ },
156
+ devServer: {
157
+ headers: {
158
+ 'Access-Control-Allow-Origin': '*',
159
+ },
160
+ allowedHosts: 'auto',
161
+ client: {
162
+ webSocketURL: {
163
+ hostname: 'localhost',
164
+ port: normalizedOptions.devServer?.port ?? 4200,
165
+ },
166
+ overlay: {
167
+ errors: true,
168
+ warnings: false,
169
+ runtimeErrors: true,
170
+ },
171
+ reconnect: true,
172
+ },
173
+ port: normalizedOptions.devServer?.port ?? 4200,
174
+ hot: false,
175
+ liveReload: true,
176
+ watchFiles: ['./src/**/*.*', './public/**/*.*'],
177
+ historyApiFallback: {
178
+ index: '/index.html',
179
+ rewrites: [{ from: /^\/$/, to: 'index.html' }],
180
+ },
181
+ devMiddleware: {
182
+ writeToDisk: (file) => !file.includes('.hot-update.'),
183
+ },
184
+ server: {
185
+ options: normalizedOptions.devServer?.sslKey &&
186
+ normalizedOptions.devServer?.sslCert
187
+ ? {
188
+ key: (0, path_1.resolve)(root, normalizedOptions.devServer.sslKey),
189
+ cert: (0, path_1.resolve)(root, normalizedOptions.devServer.sslCert),
190
+ }
191
+ : {},
192
+ type: normalizedOptions.devServer?.ssl ? 'https' : 'http',
193
+ },
194
+ proxy: await (0, dev_server_config_utils_1.getProxyConfig)(root, normalizedOptions.devServer?.proxyConfig),
195
+ },
196
+ optimization: {
197
+ chunkIds: normalizedOptions.namedChunks ? 'named' : 'deterministic',
198
+ moduleIds: 'deterministic',
199
+ ...(normalizedOptions.optimization && !isDevServer
200
+ ? {
201
+ minimize: true,
202
+ runtimeChunk: 'single',
203
+ splitChunks: {
204
+ chunks: 'async',
205
+ minChunks: 1,
206
+ minSize: 20000,
207
+ maxAsyncRequests: 30,
208
+ maxInitialRequests: 30,
209
+ cacheGroups: {
210
+ default: normalizedOptions.commonChunk && {
211
+ chunks: 'async',
212
+ minChunks: 2,
213
+ priority: 10,
214
+ },
215
+ common: normalizedOptions.commonChunk && {
216
+ name: 'common',
217
+ chunks: 'async',
218
+ minChunks: 2,
219
+ enforce: true,
220
+ priority: 5,
221
+ },
222
+ vendors: false,
223
+ defaultVendors: normalizedOptions.vendorChunk && {
224
+ name: 'vendor',
225
+ chunks: (chunk) => chunk.name === 'main',
226
+ enforce: true,
227
+ test: VENDORS_TEST,
228
+ },
229
+ },
230
+ },
231
+ minimizer: [
232
+ new core_1.SwcJsMinimizerRspackPlugin({
233
+ minimizerOptions: {
234
+ minify: true,
235
+ compress: {
236
+ passes: 2,
237
+ },
238
+ format: {
239
+ comments: false,
240
+ },
241
+ },
242
+ }),
243
+ ],
244
+ }
245
+ : {
246
+ minimize: false,
247
+ minimizer: [],
248
+ }),
249
+ },
250
+ plugins: [
251
+ ...(defaultConfig.plugins ?? []),
252
+ new ng_rspack_1.NgRspackPlugin({
253
+ ...normalizedOptions,
254
+ polyfills: ['zone.js/node'],
255
+ }),
256
+ ],
257
+ };
258
+ const mergedConfig = (0, webpack_merge_1.merge)(serverConfig, rspackConfigOverrides ?? {});
259
+ configs.push(mergedConfig);
260
+ }
261
+ const browserConfig = {
262
+ ...defaultConfig,
263
+ name: 'browser',
264
+ ...(normalizedOptions.hasServer && isDevServer
265
+ ? { dependencies: ['server'] }
266
+ : {}),
267
+ target: 'web',
268
+ entry: {
269
+ main: {
270
+ import: [normalizedOptions.browser],
271
+ },
272
+ },
273
+ devServer: {
274
+ headers: {
275
+ 'Access-Control-Allow-Origin': '*',
276
+ },
277
+ allowedHosts: 'auto',
278
+ client: {
279
+ webSocketURL: {
280
+ hostname: 'localhost',
281
+ port: options.devServer?.port ?? 4200,
282
+ },
283
+ overlay: {
284
+ errors: true,
285
+ warnings: false,
286
+ runtimeErrors: true,
287
+ },
288
+ reconnect: true,
289
+ },
290
+ hot: false,
291
+ liveReload: true,
292
+ watchFiles: ['./src/**/*.*', './public/**/*.*'],
293
+ historyApiFallback: {
294
+ index: '/index.html',
295
+ rewrites: [{ from: /^\/$/, to: 'index.html' }],
296
+ },
297
+ devMiddleware: {
298
+ writeToDisk: (file) => !file.includes('.hot-update.'),
299
+ },
300
+ port: options.devServer?.port ?? 4200,
301
+ server: {
302
+ options: normalizedOptions.devServer?.sslKey &&
303
+ normalizedOptions.devServer?.sslCert
304
+ ? {
305
+ key: (0, path_1.resolve)(root, normalizedOptions.devServer.sslKey),
306
+ cert: (0, path_1.resolve)(root, normalizedOptions.devServer.sslCert),
307
+ }
308
+ : {},
309
+ type: normalizedOptions.devServer?.ssl ? 'https' : 'http',
310
+ },
311
+ proxy: await (0, dev_server_config_utils_1.getProxyConfig)(root, normalizedOptions.devServer?.proxyConfig),
312
+ onListening: (devServer) => {
313
+ if (!devServer) {
314
+ throw new Error('@rspack/dev-server is not defined');
315
+ }
316
+ const port = devServer.server?.address()?.port ?? 4200;
317
+ console.log('Listening on port:', port);
318
+ },
319
+ },
320
+ output: {
321
+ ...defaultConfig.output,
322
+ hashFunction: isProduction ? 'xxhash64' : undefined,
323
+ publicPath: 'auto',
324
+ clean: true,
325
+ path: normalizedOptions.outputPath.browser,
326
+ cssFilename: `[name]${hashFormat.file}.css`,
327
+ filename: `[name]${hashFormat.chunk}.js`,
328
+ chunkFilename: `[name]${hashFormat.chunk}.js`,
329
+ scriptType: 'module',
330
+ module: true,
331
+ },
332
+ optimization: {
333
+ chunkIds: normalizedOptions.namedChunks ? 'named' : 'deterministic',
334
+ moduleIds: 'deterministic',
335
+ ...(normalizedOptions.optimization && !isDevServer
336
+ ? {
337
+ minimize: true,
338
+ runtimeChunk: false,
339
+ splitChunks: {
340
+ chunks: 'all',
341
+ minChunks: 1,
342
+ minSize: 20000,
343
+ maxAsyncRequests: 30,
344
+ maxInitialRequests: 30,
345
+ cacheGroups: {
346
+ default: normalizedOptions.commonChunk && {
347
+ chunks: 'async',
348
+ minChunks: 2,
349
+ priority: 10,
350
+ },
351
+ common: normalizedOptions.commonChunk && {
352
+ name: 'common',
353
+ chunks: 'async',
354
+ minChunks: 2,
355
+ enforce: true,
356
+ priority: 5,
357
+ },
358
+ vendors: false,
359
+ defaultVendors: normalizedOptions.vendorChunk && {
360
+ name: 'vendor',
361
+ chunks: (chunk) => chunk.name === 'main',
362
+ enforce: true,
363
+ test: VENDORS_TEST,
364
+ },
365
+ },
366
+ },
367
+ minimizer: [
368
+ new core_1.SwcJsMinimizerRspackPlugin({
369
+ minimizerOptions: {
370
+ minify: true,
371
+ mangle: true,
372
+ compress: {
373
+ passes: 2,
374
+ },
375
+ format: {
376
+ comments: false,
377
+ },
378
+ },
379
+ }),
380
+ ],
381
+ }
382
+ : {
383
+ minimize: false,
384
+ minimizer: [],
385
+ }),
386
+ },
387
+ plugins: [
388
+ ...(defaultConfig.plugins ?? []),
389
+ new ng_rspack_1.NgRspackPlugin({
390
+ ...normalizedOptions,
391
+ polyfills: ['zone.js'],
392
+ hasServer: false,
393
+ }),
394
+ ],
395
+ };
396
+ const mergedConfig = (0, webpack_merge_1.merge)(browserConfig, rspackConfigOverrides ?? {});
397
+ configs.unshift(mergedConfig);
398
+ return configs;
399
+ }
400
+ async function createConfig(defaultOptions, configurations = {}, configEnvVar = 'NGRS_CONFIG') {
401
+ const configurationMode = process.env[configEnvVar] ?? 'production';
402
+ const isDefault = configurationMode === 'default';
403
+ const isModeConfigured = configurationMode in configurations;
404
+ const mergedBuildOptionsOptions = {
405
+ ...defaultOptions.options,
406
+ ...((!isDefault && isModeConfigured
407
+ ? configurations[configurationMode]?.options
408
+ : {}) ?? {}),
409
+ };
410
+ let mergedRspackConfigOverrides = defaultOptions.rspackConfigOverrides ?? {};
411
+ if (!isDefault &&
412
+ isModeConfigured &&
413
+ configurations[configurationMode]?.rspackConfigOverrides) {
414
+ mergedRspackConfigOverrides = (0, webpack_merge_1.merge)(mergedRspackConfigOverrides, configurations[configurationMode]?.rspackConfigOverrides ?? {});
415
+ }
416
+ return _createConfig(mergedBuildOptionsOptions, mergedRspackConfigOverrides);
417
+ }
@@ -0,0 +1,3 @@
1
+ import type { DevServer } from '@rspack/core';
2
+ export declare function getProxyConfig(root: string, proxyConfig: string | undefined): Promise<DevServer['proxy'] | undefined>;
3
+ //# sourceMappingURL=dev-server-config-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev-server-config-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/config/dev-server-config-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAM9C,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,GAAG,SAAS,GAC9B,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,CA2EzC"}
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getProxyConfig = getProxyConfig;
4
+ const tslib_1 = require("tslib");
5
+ const node_assert_1 = tslib_1.__importDefault(require("node:assert"));
6
+ const node_fs_1 = require("node:fs");
7
+ const node_path_1 = require("node:path");
8
+ const node_url_1 = require("node:url");
9
+ async function getProxyConfig(root, proxyConfig) {
10
+ if (!proxyConfig) {
11
+ return undefined;
12
+ }
13
+ const proxyPath = (0, node_path_1.resolve)(root, proxyConfig);
14
+ if (!(0, node_fs_1.existsSync)(proxyPath)) {
15
+ throw new Error(`Proxy configuration file ${proxyPath} does not exist.`);
16
+ }
17
+ let proxyConfiguration;
18
+ switch ((0, node_path_1.extname)(proxyPath)) {
19
+ case '.json': {
20
+ const content = await node_fs_1.promises.readFile(proxyPath, 'utf-8');
21
+ const { parse, printParseErrorCode } = await Promise.resolve().then(() => tslib_1.__importStar(require('jsonc-parser')));
22
+ const parseErrors = [];
23
+ proxyConfiguration = parse(content, parseErrors, {
24
+ allowTrailingComma: true,
25
+ });
26
+ if (parseErrors.length > 0) {
27
+ let errorMessage = `Proxy configuration file ${proxyPath} contains parse errors:`;
28
+ for (const parseError of parseErrors) {
29
+ const { line, column } = getJsonErrorLineColumn(parseError.offset, content);
30
+ errorMessage += `\n[${line}, ${column}] ${printParseErrorCode(parseError.error)}`;
31
+ }
32
+ throw new Error(errorMessage);
33
+ }
34
+ break;
35
+ }
36
+ case '.mjs':
37
+ // Load the ESM configuration file using the TypeScript dynamic import workaround.
38
+ // Once TypeScript provides support for keeping the dynamic import this workaround can be
39
+ // changed to a direct dynamic import.
40
+ proxyConfiguration = (await loadEsmModule((0, node_url_1.pathToFileURL)(proxyPath))).default;
41
+ break;
42
+ case '.cjs':
43
+ proxyConfiguration = require(proxyPath);
44
+ break;
45
+ default:
46
+ // The file could be either CommonJS or ESM.
47
+ // CommonJS is tried first then ESM if loading fails.
48
+ try {
49
+ proxyConfiguration = require(proxyPath);
50
+ }
51
+ catch (e) {
52
+ assertIsError(e);
53
+ if (e.code !== 'ERR_REQUIRE_ESM') {
54
+ throw e;
55
+ }
56
+ // Load the ESM configuration file using the TypeScript dynamic import workaround.
57
+ // Once TypeScript provides support for keeping the dynamic import this workaround can be
58
+ // changed to a direct dynamic import.
59
+ proxyConfiguration = (await loadEsmModule((0, node_url_1.pathToFileURL)(proxyPath))).default;
60
+ }
61
+ }
62
+ return normalizeProxyConfiguration(proxyConfiguration);
63
+ }
64
+ function getJsonErrorLineColumn(offset, content) {
65
+ if (offset === 0) {
66
+ return { line: 1, column: 1 };
67
+ }
68
+ let line = 0;
69
+ let position = 0;
70
+ while (true) {
71
+ ++line;
72
+ const nextNewline = content.indexOf('\n', position);
73
+ if (nextNewline === -1 || nextNewline > offset) {
74
+ break;
75
+ }
76
+ position = nextNewline + 1;
77
+ }
78
+ return { line, column: offset - position + 1 };
79
+ }
80
+ function normalizeProxyConfiguration(proxy) {
81
+ return Array.isArray(proxy)
82
+ ? proxy
83
+ : Object.entries(proxy).map(([context, value]) => ({
84
+ context: [context],
85
+ ...value,
86
+ }));
87
+ }
88
+ function assertIsError(value) {
89
+ const isError = value instanceof Error ||
90
+ // The following is needing to identify errors coming from RxJs.
91
+ (typeof value === 'object' &&
92
+ value &&
93
+ 'name' in value &&
94
+ 'message' in value);
95
+ (0, node_assert_1.default)(isError, 'catch clause variable is not an Error instance');
96
+ }
97
+ let load;
98
+ function loadEsmModule(modulePath) {
99
+ load ??= new Function('modulePath', `return import(modulePath);`);
100
+ return load(modulePath);
101
+ }
@@ -0,0 +1,3 @@
1
+ import { OutputHashing, HashFormat } from '../models';
2
+ export declare function getOutputHashFormat(outputHashing?: OutputHashing, length?: number): HashFormat;
3
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/lib/config/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEtD,wBAAgB,mBAAmB,CACjC,aAAa,GAAE,aAAsB,EACrC,MAAM,SAAI,GACT,UAAU,CAkCZ"}
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOutputHashFormat = getOutputHashFormat;
4
+ function getOutputHashFormat(outputHashing = 'none', length = 8) {
5
+ const hashTemplate = `.[contenthash:${length}]`;
6
+ switch (outputHashing) {
7
+ case 'media':
8
+ return {
9
+ chunk: '',
10
+ extract: '',
11
+ file: hashTemplate,
12
+ script: '',
13
+ };
14
+ case 'bundles':
15
+ return {
16
+ chunk: hashTemplate,
17
+ extract: hashTemplate,
18
+ file: '',
19
+ script: hashTemplate,
20
+ };
21
+ case 'all':
22
+ return {
23
+ chunk: hashTemplate,
24
+ extract: hashTemplate,
25
+ file: hashTemplate,
26
+ script: hashTemplate,
27
+ };
28
+ case 'none':
29
+ default:
30
+ return {
31
+ chunk: '',
32
+ extract: '',
33
+ file: '',
34
+ script: '',
35
+ };
36
+ }
37
+ }