Skip to content

Commit 518a1b6

Browse files
committed
feat(angular-rspack): add watch option
1 parent 084932b commit 518a1b6

File tree

6 files changed

+38
-10
lines changed

6 files changed

+38
-10
lines changed

e2e/fixtures/rspack-csr-css/rspack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ module.exports = () => {
6363
baseHref: '/foo',
6464
subresourceIntegrity: true,
6565
crossOrigin: 'anonymous',
66+
watch: false, // Set to true when testing watch mode
6667
},
6768
},
6869
{

packages/angular-rspack/src/lib/config/config-utils/common-config.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { type Configuration, javascript } from '@rspack/core';
2-
import { resolve } from 'node:path';
1+
import { type Compiler, type Configuration, javascript } from '@rspack/core';
2+
import { join, resolve } from 'node:path';
33
import {
44
JS_ALL_EXT_REGEX,
55
TS_ALL_EXT_REGEX,
@@ -15,6 +15,7 @@ import { configureSourceMap } from './sourcemap-utils';
1515
import { StatsJsonPlugin } from '../../plugins/stats-json-plugin';
1616
import { getStatsOptions } from './get-stats-options';
1717
import { WatchFilesLogsPlugin } from '../../plugins/watch-file-logs-plugin';
18+
import { getIndexInputFile } from '../../utils/index-file/get-index-input-file';
1819

1920
export async function getCommonConfig(
2021
normalizedOptions: NormalizedAngularRspackPluginOptions,
@@ -30,6 +31,17 @@ export async function getCommonConfig(
3031
hashFormat,
3132
normalizedOptions.hasServer ? 'server' : 'browser'
3233
);
34+
const indexInputFile = join(
35+
normalizedOptions.root,
36+
getIndexInputFile(normalizedOptions.index)
37+
);
38+
const indexInputWatchPlugin = {
39+
apply: (compiler: Compiler) => {
40+
compiler.hooks.thisCompilation.tap('build-angular', (compilation) => {
41+
compilation.fileDependencies.add(indexInputFile);
42+
});
43+
},
44+
};
3345

3446
const defaultConfig: Configuration = {
3547
context: normalizedOptions.root,
@@ -68,6 +80,7 @@ export async function getCommonConfig(
6880
resolveLoader: {
6981
symlinks: !normalizedOptions.preserveSymlinks,
7082
},
83+
watch: normalizedOptions.watch,
7184
watchOptions: {
7285
poll: normalizedOptions.poll,
7386
followSymlinks: normalizedOptions.preserveSymlinks,
@@ -125,6 +138,7 @@ export async function getCommonConfig(
125138
plugins: [
126139
...sourceMapOptions.sourceMapPlugins,
127140
...(normalizedOptions.verbose ? [new WatchFilesLogsPlugin()] : []),
141+
...(normalizedOptions.watch ? [indexInputWatchPlugin] : []),
128142
...(normalizedOptions.statsJson
129143
? [
130144
new StatsJsonPlugin(

packages/angular-rspack/src/lib/models/angular-rspack-plugin-options.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ export interface SourceMap {
119119
}
120120

121121
export interface AngularRspackPluginOptions extends PluginUnsupportedOptions {
122+
/**
123+
* @deprecated This is a no-op and can be safely removed.
124+
* A list of CommonJS or AMD packages that are allowed to be used without a build time warning. Use `'*'` to allow all.
125+
*/
126+
allowedCommonJsDependencies?: string[];
122127
aot?: boolean;
123128
assets?: AssetElement[];
124129
/**
@@ -250,6 +255,10 @@ export interface AngularRspackPluginOptions extends PluginUnsupportedOptions {
250255
* Adds more details to output logging.
251256
*/
252257
verbose?: boolean;
258+
/**
259+
* Run build when files change.
260+
*/
261+
watch?: boolean;
253262
/**
254263
* @deprecated This is a no-op and can be safely removed.
255264
* The tsconfig file for web workers.
@@ -288,4 +297,5 @@ export interface NormalizedAngularRspackPluginOptions
288297
supportedBrowsers: string[];
289298
tsConfig: string;
290299
vendorChunk: boolean;
300+
watch: boolean;
291301
}

packages/angular-rspack/src/lib/models/normalize-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ export async function normalizeOptions(
297297
useTsProjectReferences: options.useTsProjectReferences ?? false,
298298
vendorChunk: options.vendorChunk ?? false,
299299
verbose: options.verbose ?? false,
300+
watch: options.watch ?? false,
300301
};
301302
}
302303

packages/angular-rspack/src/lib/models/unsupported-options.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,11 @@ export interface DevServerUnsupportedOptions {
2828
}
2929

3030
export interface PluginUnsupportedOptions {
31-
watch?: boolean;
3231
budgets?: BudgetEntry[];
33-
allowedCommonJsDependencies?: string[];
3432
appShell?: boolean;
3533
}
3634

37-
export const TOP_LEVEL_OPTIONS_PENDING_SUPPORT = [
38-
'watch',
39-
'budgets',
40-
'allowedCommonJsDependencies',
41-
'appShell',
42-
];
35+
export const TOP_LEVEL_OPTIONS_PENDING_SUPPORT = ['budgets', 'appShell'];
4336

4437
export const DEV_SERVER_OPTIONS_PENDING_SUPPORT = [
4538
'open',
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { IndexExpandedDefinition } from '../../models';
2+
3+
export function getIndexInputFile(index: IndexExpandedDefinition): string {
4+
if (typeof index === 'string') {
5+
return index;
6+
}
7+
8+
return index.input;
9+
}

0 commit comments

Comments
 (0)