Skip to content
This repository has been archived by the owner on Apr 9, 2022. It is now read-only.

Commit

Permalink
feat(@angular-devkit/build-angular): add watch mode to server
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Wiles authored and hansl committed May 30, 2018
1 parent 496456b commit e492b49
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/angular_devkit/build_angular/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ export class ServerBuilder implements Builder<BuildWebpackServerSchema> {
};

try {
webpackCompiler.run(callback);
if (options.watch) {
const watching = webpackCompiler.watch({ poll: options.poll }, callback);

// Teardown logic. Close the watcher when unsubscribed from.
return () => watching.close(() => { });
} else {
webpackCompiler.run(callback);
}
} catch (err) {
if (err) {
this.context.logger.error(
Expand Down
8 changes: 8 additions & 0 deletions packages/angular_devkit/build_angular/src/server/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ export interface BuildWebpackServerSchema {
* Use file name for lazy loaded chunks.
*/
namedChunks?: boolean;
/**
* Run build when files change.
*/
watch?: boolean;
/**
* Enable and define the file watching poll time period in milliseconds.
*/
poll?: number;
}

/**
Expand Down
11 changes: 10 additions & 1 deletion packages/angular_devkit/build_angular/src/server/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,15 @@
"type": "string"
},
"default": []
},
"watch": {
"type": "boolean",
"description": "Run build when files change.",
"default": false
},
"poll": {
"type": "number",
"description": "Enable and define the file watching poll time period in milliseconds."
}
},
"additionalProperties": false,
Expand Down Expand Up @@ -202,6 +211,6 @@
}
]
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,18 @@ describe('Server Builder', () => {
}),
).toPromise().then(done, done.fail);
}, Timeout.Standard);

it('runs watch mode', (done) => {
const overrides = { watch: true };

runTargetSpec(host, { project: 'app', target: 'server' }, overrides).pipe(
tap((buildEvent) => {
expect(buildEvent.success).toBe(true);

const fileName = join(outputPath, 'main.js');
const content = virtualFs.fileBufferToString(host.scopedSync().read(normalize(fileName)));
expect(content).toMatch(/AppServerModuleNgFactory/);
}),
).subscribe(undefined, done.fail, done);
}, Timeout.Standard);
});

0 comments on commit e492b49

Please sign in to comment.