File tree 3 files changed +46
-2
lines changed 3 files changed +46
-2
lines changed Original file line number Diff line number Diff line change 1
1
import * as webpack from 'webpack' ;
2
2
import * as path from 'path' ;
3
3
import { GlobCopyWebpackPlugin } from '../../plugins/glob-copy-webpack-plugin' ;
4
+ import { NamedLazyChunksWebpackPlugin } from '../../plugins/named-lazy-chunks-webpack-plugin' ;
4
5
import { extraEntryParser , getOutputHashFormat } from './utils' ;
5
6
import { WebpackConfigOptions } from '../webpack-config' ;
6
7
@@ -109,7 +110,8 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
109
110
] . concat ( extraRules )
110
111
} ,
111
112
plugins : [
112
- new webpack . NoEmitOnErrorsPlugin ( )
113
+ new webpack . NoEmitOnErrorsPlugin ( ) ,
114
+ // new NamedLazyChunksWebpackPlugin(),
113
115
] . concat ( extraPlugins ) ,
114
116
node : {
115
117
fs : 'empty' ,
Original file line number Diff line number Diff line change
1
+ import * as webpack from 'webpack' ;
2
+
3
+ // This is just a wrapper around webpack.NamedChunksPlugin to prevent name collisions.
4
+ export class NamedLazyChunksWebpackPlugin {
5
+ constructor ( ) {
6
+ const nameMap = new Map ( ) ;
7
+ // Append a dot and number if the name already exists.
8
+ const getNextName = ( baseName : string ) => {
9
+ let num : number | null = null ;
10
+ const name = ( ) => num !== null ? `${ baseName } .${ num } ` : baseName ;
11
+ while ( nameMap . has ( name ( ) ) ) {
12
+ num = num ? num ++ : 0 ;
13
+ }
14
+ nameMap . set ( name ( ) , true ) ;
15
+ return name ( ) ;
16
+ } ;
17
+
18
+ return new ( webpack as any ) . NamedChunksPlugin ( function ( chunk : any ) {
19
+ // Entry chunks have a name already, use it.
20
+ if ( chunk . name ) {
21
+ return chunk . name ;
22
+ }
23
+
24
+ // Try to figure out if it's a lazy loaded route.
25
+ if ( chunk . blocks
26
+ && chunk . blocks . length > 0
27
+ && chunk . blocks [ 0 ] . dependencies
28
+ && chunk . blocks [ 0 ] . dependencies . length > 0
29
+ && chunk . blocks [ 0 ] . dependencies [ 0 ] . lazyRouteChunkName
30
+ ) {
31
+ // lazyRouteChunkName was added by @ngtools /webpack.
32
+ return getNextName ( chunk . blocks [ 0 ] . dependencies [ 0 ] . lazyRouteChunkName ) ;
33
+ }
34
+
35
+ return null ;
36
+ } ) ;
37
+ }
38
+ }
Original file line number Diff line number Diff line change @@ -310,7 +310,11 @@ export class AotPlugin implements Tapable {
310
310
. map ( ( key ) => {
311
311
const value = this . _lazyRoutes [ key ] ;
312
312
if ( value !== null ) {
313
- return new ContextElementDependency ( value , key ) ;
313
+ const dep = new ContextElementDependency ( value , key ) ;
314
+ // lazyRouteChunkName is used by webpack.NamedChunksPlugin to give the
315
+ // lazy loaded chunk a name.
316
+ dep . lazyRouteChunkName = path . basename ( key , '.ts' ) ;
317
+ return dep ;
314
318
} else {
315
319
return null ;
316
320
}
You can’t perform that action at this time.
0 commit comments