@@ -22,6 +22,7 @@ import * as ts from 'typescript';
22
22
import * as url from 'url' ;
23
23
import * as webpack from 'webpack' ;
24
24
import * as WebpackDevServer from 'webpack-dev-server' ;
25
+ import { normalizeExtraEntryPoints } from '../angular-cli-files/models/webpack-configs/utils' ;
25
26
import { IndexHtmlWebpackPlugin } from '../angular-cli-files/plugins/index-html-webpack-plugin' ;
26
27
import { checkPort } from '../angular-cli-files/utilities/check-port' ;
27
28
import { IndexHtmlTransform } from '../angular-cli-files/utilities/index-file/write-index-html' ;
@@ -175,7 +176,7 @@ export function serveWebpackBrowser(
175
176
176
177
// Add live reload config.
177
178
if ( options . liveReload ) {
178
- _addLiveReload ( options , browserOptions , webpackConfig , clientAddress , context . logger ) ;
179
+ _addLiveReload ( root , options , browserOptions , webpackConfig , clientAddress , context . logger ) ;
179
180
} else if ( options . hmr ) {
180
181
context . logger . warn ( 'Live reload is disabled. HMR option ignored.' ) ;
181
182
}
@@ -493,6 +494,7 @@ export function buildServePath(
493
494
* @private
494
495
*/
495
496
function _addLiveReload (
497
+ root : string ,
496
498
options : DevServerBuilderOptions ,
497
499
browserOptions : BrowserBuilderSchema ,
498
500
webpackConfig : webpack . Configuration ,
@@ -557,7 +559,6 @@ function _addLiveReload(
557
559
const entryPoints = [ `${ webpackDevServerPath } ?${ url . format ( clientAddress ) } ${ sockjsPath } ` ] ;
558
560
if ( options . hmr ) {
559
561
const webpackHmrLink = 'https://webpack.js.org/guides/hot-module-replacement' ;
560
-
561
562
logger . warn ( tags . oneLine `NOTICE: Hot Module Replacement (HMR) is enabled for the dev server.` ) ;
562
563
563
564
const showWarning = options . hmrWarning ;
@@ -574,11 +575,15 @@ function _addLiveReload(
574
575
) ;
575
576
}
576
577
entryPoints . push ( 'webpack/hot/dev-server' ) ;
577
- webpackConfig . plugins . push ( new webpack . HotModuleReplacementPlugin ( ) ) ;
578
- if ( browserOptions . extractCss ) {
579
- logger . warn ( tags . oneLine `NOTICE: (HMR) does not allow for CSS hot reload
580
- when used together with '--extract-css'.` ) ;
578
+ if ( browserOptions . styles ?. length ) {
579
+ // When HMR is enabled we need to add the css paths as part of the entrypoints
580
+ // because otherwise no JS bundle will contain the HMR accept code.
581
+ const normalizedStyles = normalizeExtraEntryPoints ( browserOptions . styles , 'styles' )
582
+ . map ( style => path . resolve ( root , style . input ) ) ;
583
+ entryPoints . push ( ...normalizedStyles ) ;
581
584
}
585
+
586
+ webpackConfig . plugins . push ( new webpack . HotModuleReplacementPlugin ( ) ) ;
582
587
}
583
588
if ( typeof webpackConfig . entry !== 'object' || Array . isArray ( webpackConfig . entry ) ) {
584
589
webpackConfig . entry = { } ;
0 commit comments