Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit e492b49

Browse files
Fabian Wileshansl
Fabian Wiles
authored andcommitted
feat(@angular-devkit/build-angular): add watch mode to server
1 parent 496456b commit e492b49

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

packages/angular_devkit/build_angular/src/server/index.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,14 @@ export class ServerBuilder implements Builder<BuildWebpackServerSchema> {
8585
};
8686

8787
try {
88-
webpackCompiler.run(callback);
88+
if (options.watch) {
89+
const watching = webpackCompiler.watch({ poll: options.poll }, callback);
90+
91+
// Teardown logic. Close the watcher when unsubscribed from.
92+
return () => watching.close(() => { });
93+
} else {
94+
webpackCompiler.run(callback);
95+
}
8996
} catch (err) {
9097
if (err) {
9198
this.context.logger.error(

packages/angular_devkit/build_angular/src/server/schema.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ export interface BuildWebpackServerSchema {
117117
* Use file name for lazy loaded chunks.
118118
*/
119119
namedChunks?: boolean;
120+
/**
121+
* Run build when files change.
122+
*/
123+
watch?: boolean;
124+
/**
125+
* Enable and define the file watching poll time period in milliseconds.
126+
*/
127+
poll?: number;
120128
}
121129

122130
/**

packages/angular_devkit/build_angular/src/server/schema.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@
157157
"type": "string"
158158
},
159159
"default": []
160+
},
161+
"watch": {
162+
"type": "boolean",
163+
"description": "Run build when files change.",
164+
"default": false
165+
},
166+
"poll": {
167+
"type": "number",
168+
"description": "Enable and define the file watching poll time period in milliseconds."
160169
}
161170
},
162171
"additionalProperties": false,
@@ -202,6 +211,6 @@
202211
}
203212
]
204213
}
205-
214+
206215
}
207216
}

packages/angular_devkit/build_angular/test/server/base_spec_large.ts

+14
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,18 @@ describe('Server Builder', () => {
4545
}),
4646
).toPromise().then(done, done.fail);
4747
}, Timeout.Standard);
48+
49+
it('runs watch mode', (done) => {
50+
const overrides = { watch: true };
51+
52+
runTargetSpec(host, { project: 'app', target: 'server' }, overrides).pipe(
53+
tap((buildEvent) => {
54+
expect(buildEvent.success).toBe(true);
55+
56+
const fileName = join(outputPath, 'main.js');
57+
const content = virtualFs.fileBufferToString(host.scopedSync().read(normalize(fileName)));
58+
expect(content).toMatch(/AppServerModuleNgFactory/);
59+
}),
60+
).subscribe(undefined, done.fail, done);
61+
}, Timeout.Standard);
4862
});

0 commit comments

Comments
 (0)