Skip to content

Commit 86c8db5

Browse files
jschwartyMRHarrison
authored andcommitted
feat(serve): add --hmr flag for HotModuleReplacement support (angular#3330)
1 parent 3c0b8cd commit 86c8db5

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

packages/angular-cli/commands/serve.ts

+7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface ServeTaskOptions {
3131
progress?: boolean;
3232
open?: boolean;
3333
vendorChunk?: boolean;
34+
hmr?: boolean;
3435
}
3536

3637
const ServeCommand = Command.extend({
@@ -96,6 +97,12 @@ const ServeCommand = Command.extend({
9697
aliases: ['o'],
9798
description: 'Opens the url in default browser',
9899
},
100+
{
101+
name: 'hmr',
102+
type: Boolean,
103+
default: false,
104+
description: 'Enable hot module replacement',
105+
},
99106
],
100107

101108
run: function(commandOptions: ServeTaskOptions) {

packages/angular-cli/tasks/serve-webpack.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,23 @@ export default Task.extend({
3434

3535
// This allows for live reload of page when changes are made to repo.
3636
// https://webpack.github.io/docs/webpack-dev-server.html#inline-mode
37-
config.entry.main.unshift(
37+
let entryPoints = [
3838
`webpack-dev-server/client?http://${serveTaskOptions.host}:${serveTaskOptions.port}/`
39-
);
39+
];
40+
if (serveTaskOptions.hmr) {
41+
const webpackHmrLink = 'https://webpack.github.io/docs/hot-module-replacement.html';
42+
ui.writeLine(oneLine`
43+
${chalk.yellow('NOTICE')} Hot Module Replacement (HMR) is enabled for the dev server.
44+
`);
45+
ui.writeLine(' The project will still live reload when HMR is enabled,');
46+
ui.writeLine(' but to take advantage of HMR additional application code is required');
47+
ui.writeLine(' (not included in an angular-cli project by default).');
48+
ui.writeLine(` See ${chalk.blue(webpackHmrLink)}`);
49+
ui.writeLine(' for information on working with HMR for Webpack.');
50+
entryPoints.push('webpack/hot/dev-server');
51+
config.plugins.push(new webpack.HotModuleReplacementPlugin());
52+
}
53+
config.entry.main.unshift(...entryPoints);
4054
webpackCompiler = webpack(config);
4155

4256
const statsConfig = getWebpackStatsConfig(serveTaskOptions.verbose);
@@ -90,6 +104,8 @@ export default Task.extend({
90104
webpackDevServerConfiguration.cert = sslCert;
91105
}
92106

107+
webpackDevServerConfiguration.hot = serveTaskOptions.hmr;
108+
93109
ui.writeLine(chalk.green(oneLine`
94110
**
95111
NG Live Development Server is running on

0 commit comments

Comments
 (0)