@@ -65,6 +65,24 @@ const devServerBuildOverriddenKeys: (keyof DevServerBuilderOptions)[] = [
6565 'deployUrl' ,
6666] ;
6767
68+ // Get dev-server only options.
69+ type DevServerOptions = Partial <
70+ Omit <
71+ Schema ,
72+ | 'watch'
73+ | 'optimization'
74+ | 'aot'
75+ | 'sourceMap'
76+ | 'vendorChunk'
77+ | 'commonChunk'
78+ | 'baseHref'
79+ | 'progress'
80+ | 'poll'
81+ | 'verbose'
82+ | 'deployUrl'
83+ >
84+ > ;
85+
6886/**
6987 * @experimental Direct usage of this type is considered experimental.
7088 */
@@ -119,23 +137,6 @@ export function serveWebpackBrowser(
119137 { } ,
120138 ) ;
121139
122- // Get dev-server only options.
123- type DevServerOptions = Partial <
124- Omit <
125- Schema ,
126- | 'watch'
127- | 'optimization'
128- | 'aot'
129- | 'sourceMap'
130- | 'vendorChunk'
131- | 'commonChunk'
132- | 'baseHref'
133- | 'progress'
134- | 'poll'
135- | 'verbose'
136- | 'deployUrl'
137- >
138- > ;
139140 const devServerOptions : DevServerOptions = ( Object . keys ( options ) as ( keyof Schema ) [ ] )
140141 . filter ( ( key ) => ! devServerBuildOverriddenKeys . includes ( key ) && key !== 'browserTarget' )
141142 . reduce < DevServerOptions > (
@@ -156,6 +157,36 @@ export function serveWebpackBrowser(
156157 logger . warn ( `Warning: 'outputHashing' option is disabled when using the dev-server.` ) ;
157158 }
158159
160+ if ( options . hmr ) {
161+ logger . warn ( tags . stripIndents `NOTICE: Hot Module Replacement (HMR) is enabled for the dev server.
162+ See https://webpack.js.org/guides/hot-module-replacement for information on working with HMR for Webpack.` ) ;
163+ }
164+
165+ if (
166+ ! options . disableHostCheck &&
167+ options . host &&
168+ ! / ^ 1 2 7 \. \d + \. \d + \. \d + / g. test ( options . host ) &&
169+ options . host !== 'localhost'
170+ ) {
171+ logger . warn ( tags . stripIndent `
172+ Warning: This is a simple server for use in testing or debugging Angular applications
173+ locally. It hasn't been reviewed for security issues.
174+
175+ Binding this server to an open connection can result in compromising your application or
176+ computer. Using a different host than the one passed to the "--host" flag might result in
177+ websocket connection issues. You might need to use "--disableHostCheck" if that's the
178+ case.
179+ ` ) ;
180+ }
181+
182+ if ( options . disableHostCheck ) {
183+ logger . warn ( tags . oneLine `
184+ Warning: Running a server with --disable-host-check is a security risk.
185+ See https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a
186+ for more information.
187+ ` ) ;
188+ }
189+
159190 // Webpack's live reload functionality adds the `strip-ansi` package which is commonJS
160191 rawBrowserOptions . allowedCommonJsDependencies ??= [ ] ;
161192 rawBrowserOptions . allowedCommonJsDependencies . push ( 'strip-ansi' ) ;
@@ -166,6 +197,18 @@ export function serveWebpackBrowser(
166197 browserName ,
167198 ) ) as json . JsonObject & BrowserBuilderSchema ;
168199
200+ const { styles, scripts } = normalizeOptimization ( browserOptions . optimization ) ;
201+ if ( scripts || styles . minify ) {
202+ logger . error ( tags . stripIndents `
203+ ****************************************************************************************
204+ This is a simple server for use in testing or debugging Angular applications locally.
205+ It hasn't been reviewed for security issues.
206+
207+ DON'T USE IT FOR PRODUCTION!
208+ ****************************************************************************************
209+ ` ) ;
210+ }
211+
169212 const { config, projectRoot, i18n } = await generateI18nBrowserWebpackConfigFromContext (
170213 browserOptions ,
171214 context ,
@@ -220,36 +263,6 @@ export function serveWebpackBrowser(
220263 }
221264 }
222265
223- if ( options . hmr ) {
224- logger . warn ( tags . stripIndents `NOTICE: Hot Module Replacement (HMR) is enabled for the dev server.
225- See https://webpack.js.org/guides/hot-module-replacement for information on working with HMR for Webpack.` ) ;
226- }
227-
228- if (
229- ! options . disableHostCheck &&
230- options . host &&
231- ! / ^ 1 2 7 \. \d + \. \d + \. \d + / g. test ( options . host ) &&
232- options . host !== 'localhost'
233- ) {
234- logger . warn ( tags . stripIndent `
235- Warning: This is a simple server for use in testing or debugging Angular applications
236- locally. It hasn't been reviewed for security issues.
237-
238- Binding this server to an open connection can result in compromising your application or
239- computer. Using a different host than the one passed to the "--host" flag might result in
240- websocket connection issues. You might need to use "--disableHostCheck" if that's the
241- case.
242- ` ) ;
243- }
244-
245- if ( options . disableHostCheck ) {
246- logger . warn ( tags . oneLine `
247- Warning: Running a server with --disable-host-check is a security risk.
248- See https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a
249- for more information.
250- ` ) ;
251- }
252-
253266 let locale : string | undefined ;
254267 if ( i18n . shouldInline ) {
255268 // Dev-server only supports one locale
@@ -290,8 +303,6 @@ export function serveWebpackBrowser(
290303
291304 return from ( setup ( ) ) . pipe (
292305 switchMap ( ( { browserOptions, webpackConfig, projectRoot, locale } ) => {
293- const normalizedOptimization = normalizeOptimization ( browserOptions . optimization ) ;
294-
295306 if ( browserOptions . index ) {
296307 const { scripts = [ ] , styles = [ ] , baseHref, tsConfig } = browserOptions ;
297308 const { options : compilerOptions } = readTsconfig ( tsConfig , workspaceRoot ) ;
@@ -315,25 +326,14 @@ export function serveWebpackBrowser(
315326 deployUrl : browserOptions . deployUrl ,
316327 sri : browserOptions . subresourceIntegrity ,
317328 postTransform : transforms . indexHtml ,
318- optimization : normalizedOptimization ,
329+ optimization : normalizeOptimization ( browserOptions . optimization ) ,
319330 WOFFSupportNeeded : ! buildBrowserFeatures . isFeatureSupported ( 'woff2' ) ,
320331 crossOrigin : browserOptions . crossOrigin ,
321332 lang : locale ,
322333 } ) ,
323334 ) ;
324335 }
325336
326- if ( normalizedOptimization . scripts || normalizedOptimization . styles . minify ) {
327- logger . error ( tags . stripIndents `
328- ****************************************************************************************
329- This is a simple server for use in testing or debugging Angular applications locally.
330- It hasn't been reviewed for security issues.
331-
332- DON'T USE IT FOR PRODUCTION!
333- ****************************************************************************************
334- ` ) ;
335- }
336-
337337 return runWebpackDevServer ( webpackConfig , context , {
338338 logging : transforms . logging || createWebpackLoggingCallback ( ! ! options . verbose , logger ) ,
339339 webpackFactory : require ( 'webpack' ) as typeof webpack ,
0 commit comments