@@ -31,6 +31,7 @@ const definePluginUtil = require('./plugins/define');
3131const uglifyPluginUtil = require ( './plugins/uglify' ) ;
3232const friendlyErrorPluginUtil = require ( './plugins/friendly-errors' ) ;
3333const assetOutputDisplay = require ( './plugins/asset-output-display' ) ;
34+ const PluginPriorities = require ( './plugins/plugin-priorities' ) ;
3435
3536class ConfigGenerator {
3637 /**
@@ -207,7 +208,7 @@ class ConfigGenerator {
207208 }
208209
209210 buildPluginsConfig ( ) {
210- let plugins = [ ] ;
211+ const plugins = [ ] ;
211212
212213 extractTextPluginUtil ( plugins , this . webpackConfig ) ;
213214
@@ -232,15 +233,31 @@ class ConfigGenerator {
232233 uglifyPluginUtil ( plugins , this . webpackConfig ) ;
233234
234235 const friendlyErrorPlugin = friendlyErrorPluginUtil ( this . webpackConfig ) ;
235- plugins . push ( friendlyErrorPlugin ) ;
236+ plugins . push ( {
237+ plugin : friendlyErrorPlugin ,
238+ priority : PluginPriorities . FriendlyErrorsWebpackPlugin
239+ } ) ;
236240
237241 assetOutputDisplay ( plugins , this . webpackConfig , friendlyErrorPlugin ) ;
238242
239243 this . webpackConfig . plugins . forEach ( function ( plugin ) {
240244 plugins . push ( plugin ) ;
241245 } ) ;
242246
243- return plugins ;
247+ // Return sorted plugins
248+ return plugins
249+ . map ( ( plugin , position ) => Object . assign ( { } , plugin , { position : position } ) )
250+ . sort ( ( a , b ) => {
251+ // Keep the original order if two plugins have the same priority
252+ if ( a . priority === b . priority ) {
253+ return a . position - b . position ;
254+ }
255+
256+ // A plugin with a priority of -10 will be placed after one
257+ // that has a priority of 0.
258+ return b . priority - a . priority ;
259+ } )
260+ . map ( ( plugin ) => plugin . plugin ) ;
244261 }
245262
246263 buildStatsConfig ( ) {
0 commit comments