Skip to content

feat(angular-rspack): add watch option #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions e2e/fixtures/rspack-csr-css/rspack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ module.exports = () => {
baseHref: '/foo',
subresourceIntegrity: true,
crossOrigin: 'anonymous',
watch: false, // Set to true when testing watch mode
},
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Configuration, javascript } from '@rspack/core';
import { resolve } from 'node:path';
import { type Compiler, type Configuration, javascript } from '@rspack/core';
import { join, resolve } from 'node:path';
import {
JS_ALL_EXT_REGEX,
TS_ALL_EXT_REGEX,
Expand All @@ -15,6 +15,7 @@ import { configureSourceMap } from './sourcemap-utils';
import { StatsJsonPlugin } from '../../plugins/stats-json-plugin';
import { getStatsOptions } from './get-stats-options';
import { WatchFilesLogsPlugin } from '../../plugins/watch-file-logs-plugin';
import { getIndexInputFile } from '../../utils/index-file/get-index-input-file';

export async function getCommonConfig(
normalizedOptions: NormalizedAngularRspackPluginOptions,
Expand All @@ -30,6 +31,17 @@ export async function getCommonConfig(
hashFormat,
normalizedOptions.hasServer ? 'server' : 'browser'
);
const indexInputFile = join(
normalizedOptions.root,
getIndexInputFile(normalizedOptions.index)
);
const indexInputWatchPlugin = {
apply: (compiler: Compiler) => {
compiler.hooks.thisCompilation.tap('build-angular', (compilation) => {
compilation.fileDependencies.add(indexInputFile);
});
},
};

const defaultConfig: Configuration = {
context: normalizedOptions.root,
Expand Down Expand Up @@ -68,6 +80,7 @@ export async function getCommonConfig(
resolveLoader: {
symlinks: !normalizedOptions.preserveSymlinks,
},
watch: normalizedOptions.watch,
watchOptions: {
poll: normalizedOptions.poll,
followSymlinks: normalizedOptions.preserveSymlinks,
Expand Down Expand Up @@ -125,6 +138,7 @@ export async function getCommonConfig(
plugins: [
...sourceMapOptions.sourceMapPlugins,
...(normalizedOptions.verbose ? [new WatchFilesLogsPlugin()] : []),
...(normalizedOptions.watch ? [indexInputWatchPlugin] : []),
...(normalizedOptions.statsJson
? [
new StatsJsonPlugin(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,21 @@ describe('createConfig', () => {
createConfig({
options: {
...configBase,
watch: true,
appShell: true,
devServer: { allowedHosts: ['localhost'] },
},
})
).resolves.not.toContain([
expect.objectContaining({
watch: true,
appShell: true,
devServer: expect.objectContaining({
allowedHosts: ['localhost'],
}),
}),
]);
expect(warnSpy).toHaveBeenCalledWith(
`The following options are not yet supported:
"watch"
"appShell"
`
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ export interface SourceMap {
}

export interface AngularRspackPluginOptions extends PluginUnsupportedOptions {
/**
* @deprecated This is a no-op and can be safely removed.
* A list of CommonJS or AMD packages that are allowed to be used without a build time warning. Use `'*'` to allow all.
*/
allowedCommonJsDependencies?: string[];
aot?: boolean;
assets?: AssetElement[];
/**
Expand Down Expand Up @@ -250,6 +255,10 @@ export interface AngularRspackPluginOptions extends PluginUnsupportedOptions {
* Adds more details to output logging.
*/
verbose?: boolean;
/**
* Run build when files change.
*/
watch?: boolean;
/**
* @deprecated This is a no-op and can be safely removed.
* The tsconfig file for web workers.
Expand Down Expand Up @@ -288,4 +297,5 @@ export interface NormalizedAngularRspackPluginOptions
supportedBrowsers: string[];
tsConfig: string;
vendorChunk: boolean;
watch: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export async function normalizeOptions(
useTsProjectReferences: options.useTsProjectReferences ?? false,
vendorChunk: options.vendorChunk ?? false,
verbose: options.verbose ?? false,
watch: options.watch ?? false,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,11 @@ export interface DevServerUnsupportedOptions {
}

export interface PluginUnsupportedOptions {
watch?: boolean;
budgets?: BudgetEntry[];
allowedCommonJsDependencies?: string[];
appShell?: boolean;
}

export const TOP_LEVEL_OPTIONS_PENDING_SUPPORT = [
'watch',
'budgets',
'allowedCommonJsDependencies',
'appShell',
];
export const TOP_LEVEL_OPTIONS_PENDING_SUPPORT = ['budgets', 'appShell'];

export const DEV_SERVER_OPTIONS_PENDING_SUPPORT = [
'open',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { IndexExpandedDefinition } from '../../models';

export function getIndexInputFile(index: IndexExpandedDefinition): string {
if (typeof index === 'string') {
return index;
}

return index.input;
}