Skip to content

Commit

Permalink
feat(serve): add --hmr flag for HotModuleReplacement support (#3330)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwarty authored and hansl committed Dec 1, 2016
1 parent ed305a2 commit 46efa9e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions packages/angular-cli/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface ServeTaskOptions {
progress?: boolean;
open?: boolean;
vendorChunk?: boolean;
hmr?: boolean;
}

const ServeCommand = Command.extend({
Expand Down Expand Up @@ -96,6 +97,12 @@ const ServeCommand = Command.extend({
aliases: ['o'],
description: 'Opens the url in default browser',
},
{
name: 'hmr',
type: Boolean,
default: false,
description: 'Enable hot module replacement',
},
],

run: function(commandOptions: ServeTaskOptions) {
Expand Down
20 changes: 18 additions & 2 deletions packages/angular-cli/tasks/serve-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,23 @@ export default Task.extend({

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

const statsConfig = getWebpackStatsConfig(serveTaskOptions.verbose);
Expand Down Expand Up @@ -90,6 +104,8 @@ export default Task.extend({
webpackDevServerConfiguration.cert = sslCert;
}

webpackDevServerConfiguration.hot = serveTaskOptions.hmr;

ui.writeLine(chalk.green(oneLine`
**
NG Live Development Server is running on
Expand Down

0 comments on commit 46efa9e

Please sign in to comment.