Skip to content

Commit b989e80

Browse files
beemanBrocco
authored andcommitted
feat(@angular/cli): allow disabling warning when --hmr flag is enabled
1 parent 9bd6d43 commit b989e80

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

packages/@angular/cli/lib/config/schema.json

+5
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,11 @@
493493
"description": "Allow people to disable console warnings.",
494494
"type": "object",
495495
"properties": {
496+
"hmrWarning": {
497+
"description": "Show a warning when the user enabled the --hmr option.",
498+
"type": "boolean",
499+
"default": true
500+
},
496501
"nodeDeprecation": {
497502
"description": "Show a warning when the node version is incompatible.",
498503
"type": "boolean",

packages/@angular/cli/tasks/serve.ts

+18-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const WebpackDevServer = require('webpack-dev-server');
1515
const Task = require('../ember-cli/lib/models/task');
1616
const SilentError = require('silent-error');
1717
const opn = require('opn');
18+
const yellow = require('chalk').yellow;
1819

1920
export default Task.extend({
2021
run: function (serveTaskOptions: ServeTaskOptions, rebuildDoneCb: any) {
@@ -52,7 +53,7 @@ export default Task.extend({
5253

5354
if (serveTaskOptions.disableHostCheck) {
5455
ui.writeLine(oneLine`
55-
${chalk.yellow('WARNING')} Running a server with --disable-host-check is a security risk.
56+
${yellow('WARNING')} Running a server with --disable-host-check is a security risk.
5657
See https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a
5758
for more information.
5859
`);
@@ -77,27 +78,35 @@ export default Task.extend({
7778
];
7879
if (serveTaskOptions.hmr) {
7980
const webpackHmrLink = 'https://webpack.github.io/docs/hot-module-replacement.html';
81+
8082
ui.writeLine(oneLine`
81-
${chalk.yellow('NOTICE')} Hot Module Replacement (HMR) is enabled for the dev server.
83+
${yellow('NOTICE')} Hot Module Replacement (HMR) is enabled for the dev server.
8284
`);
83-
ui.writeLine(' The project will still live reload when HMR is enabled,');
84-
ui.writeLine(' but to take advantage of HMR additional application code is required');
85-
ui.writeLine(' (not included in an Angular CLI project by default).');
86-
ui.writeLine(` See ${chalk.blue(webpackHmrLink)}`);
87-
ui.writeLine(' for information on working with HMR for Webpack.');
85+
86+
const showWarning = CliConfig.fromGlobal().get('warnings.hmrWarning');
87+
if (showWarning) {
88+
ui.writeLine(' The project will still live reload when HMR is enabled,');
89+
ui.writeLine(' but to take advantage of HMR additional application code is required');
90+
ui.writeLine(' (not included in an Angular CLI project by default).');
91+
ui.writeLine(` See ${chalk.blue(webpackHmrLink)}`);
92+
ui.writeLine(' for information on working with HMR for Webpack.');
93+
ui.writeLine(oneLine`
94+
${yellow('To disable this warning use "ng set --global warnings.hmrWarning=false"')}
95+
`);
96+
}
8897
entryPoints.push('webpack/hot/dev-server');
8998
webpackConfig.plugins.push(new webpack.HotModuleReplacementPlugin());
9099
if (serveTaskOptions.extractCss) {
91100
ui.writeLine(oneLine`
92-
${chalk.yellow('NOTICE')} (HMR) does not allow for CSS hot reload when used
101+
${yellow('NOTICE')} (HMR) does not allow for CSS hot reload when used
93102
together with '--extract-css'.
94103
`);
95104
}
96105
}
97106
if (!webpackConfig.entry.main) { webpackConfig.entry.main = []; }
98107
webpackConfig.entry.main.unshift(...entryPoints);
99108
} else if (serveTaskOptions.hmr) {
100-
ui.writeLine(chalk.yellow('Live reload is disabled. HMR option ignored.'));
109+
ui.writeLine(yellow('Live reload is disabled. HMR option ignored.'));
101110
}
102111

103112
if (!serveTaskOptions.watch) {

0 commit comments

Comments
 (0)