@@ -65,6 +65,24 @@ const devServerBuildOverriddenKeys: (keyof DevServerBuilderOptions)[] = [
65
65
'deployUrl' ,
66
66
] ;
67
67
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
+
68
86
/**
69
87
* @experimental Direct usage of this type is considered experimental.
70
88
*/
@@ -119,23 +137,6 @@ export function serveWebpackBrowser(
119
137
{ } ,
120
138
) ;
121
139
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
- > ;
139
140
const devServerOptions : DevServerOptions = ( Object . keys ( options ) as ( keyof Schema ) [ ] )
140
141
. filter ( ( key ) => ! devServerBuildOverriddenKeys . includes ( key ) && key !== 'browserTarget' )
141
142
. reduce < DevServerOptions > (
@@ -156,6 +157,36 @@ export function serveWebpackBrowser(
156
157
logger . warn ( `Warning: 'outputHashing' option is disabled when using the dev-server.` ) ;
157
158
}
158
159
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
+
159
190
// Webpack's live reload functionality adds the `strip-ansi` package which is commonJS
160
191
rawBrowserOptions . allowedCommonJsDependencies ??= [ ] ;
161
192
rawBrowserOptions . allowedCommonJsDependencies . push ( 'strip-ansi' ) ;
@@ -166,6 +197,18 @@ export function serveWebpackBrowser(
166
197
browserName ,
167
198
) ) as json . JsonObject & BrowserBuilderSchema ;
168
199
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
+
169
212
const { config, projectRoot, i18n } = await generateI18nBrowserWebpackConfigFromContext (
170
213
browserOptions ,
171
214
context ,
@@ -220,36 +263,6 @@ export function serveWebpackBrowser(
220
263
}
221
264
}
222
265
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
-
253
266
let locale : string | undefined ;
254
267
if ( i18n . shouldInline ) {
255
268
// Dev-server only supports one locale
@@ -290,8 +303,6 @@ export function serveWebpackBrowser(
290
303
291
304
return from ( setup ( ) ) . pipe (
292
305
switchMap ( ( { browserOptions, webpackConfig, projectRoot, locale } ) => {
293
- const normalizedOptimization = normalizeOptimization ( browserOptions . optimization ) ;
294
-
295
306
if ( browserOptions . index ) {
296
307
const { scripts = [ ] , styles = [ ] , baseHref, tsConfig } = browserOptions ;
297
308
const { options : compilerOptions } = readTsconfig ( tsConfig , workspaceRoot ) ;
@@ -315,25 +326,14 @@ export function serveWebpackBrowser(
315
326
deployUrl : browserOptions . deployUrl ,
316
327
sri : browserOptions . subresourceIntegrity ,
317
328
postTransform : transforms . indexHtml ,
318
- optimization : normalizedOptimization ,
329
+ optimization : normalizeOptimization ( browserOptions . optimization ) ,
319
330
WOFFSupportNeeded : ! buildBrowserFeatures . isFeatureSupported ( 'woff2' ) ,
320
331
crossOrigin : browserOptions . crossOrigin ,
321
332
lang : locale ,
322
333
} ) ,
323
334
) ;
324
335
}
325
336
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
-
337
337
return runWebpackDevServer ( webpackConfig , context , {
338
338
logging : transforms . logging || createWebpackLoggingCallback ( ! ! options . verbose , logger ) ,
339
339
webpackFactory : require ( 'webpack' ) as typeof webpack ,
0 commit comments