Skip to content
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

feat(serve): add --hmr flag #3330

Merged
merged 6 commits into from
Dec 1, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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