@@ -6,6 +6,7 @@ var path = require('path');
66
77var EntrypointsOverSizeLimitWarning = require ( './EntrypointsOverSizeLimitWarning' ) ;
88var AssetsOverSizeLimitWarning = require ( './AssetsOverSizeLimitWarning' ) ;
9+ var NoAsyncChunksWarning = require ( './NoAsyncChunksWarning' ) ;
910
1011function EmittedAssetSizeLimitPlugin ( performanceOptions ) {
1112 this . maxAssetSize = performanceOptions . maxAssetSize ;
@@ -53,7 +54,6 @@ EmittedAssetSizeLimitPlugin.prototype.apply = function(compiler) {
5354 compiler . plugin ( "emit" , function ( compilation , callback ) {
5455 var warnings = [ ] ;
5556 var assetsByFile = { } ;
56- var assetsByChunkName = { } ;
5757 var assetsOverSizeLimit = [ ] ;
5858 var entrypointsOverSizeLimit = [ ] ;
5959
@@ -86,81 +86,62 @@ EmittedAssetSizeLimitPlugin.prototype.apply = function(compiler) {
8686 } ) ;
8787 if ( chunk . name ) {
8888 assetsByFile [ asset ] . chunkNames . push ( chunk . name ) ;
89- if ( assetsByChunkName [ chunk . name ] ) {
90- assetsByChunkName [ chunk . name ] = [ ] . concat ( assetsByChunkName [ chunk . name ] ) . concat ( [ asset ] ) ;
91- } else {
92- assetsByChunkName [ chunk . name ] = asset ;
93- }
9489 }
9590 }
9691 } ) ;
9792 } ) ;
9893
9994 var hasAsyncChunks = compilation . chunks . filter ( function ( chunk ) {
100- return chunk . isAsync ( ) ;
95+ return ! chunk . isInitial ( ) ;
10196 } ) . length > 0 ;
10297
103- var entrypoints = Object . keys ( compilation . entrypoints ) . map ( function ( ep ) {
104- var files = [ ] ;
105- var entrypoint = compilation . entrypoints [ ep ] ;
98+ var entrypointsOverLimit = Object . keys ( compilation . entrypoints )
99+ . map ( function ( key ) {
100+ return compilation . entrypoints [ key ]
101+ } )
102+ . filter ( function ( entry ) {
103+ return doesExceedLimit ( entrypointSizeLimit , entry . getSize ( ) )
104+ } )
106105
107- entrypoint . assets = { } ;
108- entrypoint . size = 0 ;
109-
110- // TODO: Need to use keys or even better Set for distinct values
111- entrypoint . chunks . forEach ( function ( chunk ) {
112- chunk . files . forEach ( function ( file ) {
113- files . push ( file ) ;
114- } ) ;
115- } ) ;
116-
117- files . forEach ( function ( file ) {
118- if ( ! isAssetJsFile ( file ) ) {
119- return ;
120- }
121- entrypoint . assets [ file ] = assetsByFile [ file ] ;
122- entrypoint . size = entrypoint . size + assetsByFile [ file ] . size ;
123- entrypoint . isOverSizeLimit = false ;
124- if ( entrypoint . assets [ file ] . isOverSizeLimit ) {
125- entrypoint . isOverSizeLimit = true ;
126- }
127- } ) ;
128-
129- if ( ! entrypoint . isOverSizeLimit ) {
130- entrypoint . isOverSizeLimit = doesExceedLimit ( entrypointSizeLimit , formatSize ( entrypoint . size ) . number ) ;
131- }
132-
133- return entrypoint ;
134- } ) ;
135-
136- entrypointsOverSizeLimit = entrypoints . filter ( function ( ep ) {
137- return ep . isOverSizeLimit ;
138- } )
139-
140- // 1. Individual Chunk: Size < 200kb
141- // 2. Collective Initial Chunks (Each Set?): Size < 200kb
106+ // 1. Individual Chunk: Size < 250kb
107+ // 2. Collective Initial Chunks [entrypoint] (Each Set?): Size < 250kb
142108 // 3. No Async Chunks
143109 // if !1, then 2, if !2 return
144- // if 1, then 2, then 3,
145110 if ( assetsOverSizeLimit . length ) {
146- warnings . push ( new AssetsOverSizeLimitWarning ( assetsOverSizeLimit , compilation , formatSize , sizeLimit ) ) ;
147- warnings . push ( new EntrypointsOverSizeLimitWarning ( entrypointsOverSizeLimit , compilation , formatSize , entrypointSizeLimit ) ) ;
111+ warnings . push (
112+ new AssetsOverSizeLimitWarning (
113+ assetsOverSizeLimit ,
114+ compilation ,
115+ formatSize ,
116+ sizeLimit
117+ )
118+ ) ;
119+
120+ warnings . push (
121+ new EntrypointsOverSizeLimitWarning (
122+ entrypointsOverLimit ,
123+ compilation ,
124+ formatSize ,
125+ entrypointSizeLimit
126+ )
127+ ) ;
148128
149129 if ( ! hasAsyncChunks ) {
150- warnings . push ( new Error ( "webpack performance recommendations: \n" +
151- "You can limit the size of your bundles by using System.import() or require.ensure to lazy load some parts of your application.\n" +
152- "For more info visit https://webpack.github.io/docs/code-splitting.html"
153- ) ) ;
130+ warnings . push ( new NoAsyncChunksWarning ( ) ) ;
154131 }
155132 } else {
156133 if ( entrypointsOverSizeLimit . legnth ) {
157- warnings . push ( new EntrypointsOverSizeLimitWarning ( entrypointsOverSizeLimit , compilation , formatSize , entrypointSizeLimit ) ) ;
134+ warnings . push (
135+ new EntrypointsOverSizeLimitWarning (
136+ entrypointsOverSizeLimit ,
137+ compilation ,
138+ formatSize ,
139+ entrypointSizeLimit
140+ )
141+ ) ;
158142
159143 if ( ! hasAsyncChunks ) {
160- warnings . push ( new Error ( "webpack performance recommendations: \n" +
161- "You can limit the size of your bundles by using System.import() or require.ensure to lazy load some parts of your application.\n" +
162- "For more info visit https://webpack.github.io/docs/code-splitting.html"
163- ) ) ;
144+ warnings . push ( new NoAsyncChunksWarning ( ) ) ;
164145 }
165146 }
166147 }
0 commit comments