File tree 3 files changed +39
-13
lines changed
3 files changed +39
-13
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,11 @@ Type: `function`
100
100
101
101
Modify files details before the manifest is created. [ more details] ( #hooks-options )
102
102
103
+ ### ` options.sort `
104
+
105
+ Type: ` function `
106
+
107
+ Sort files before they are passed to ` generate ` . [ more details] ( #hooks-options )
103
108
104
109
### ` options.generate `
105
110
@@ -113,7 +118,7 @@ Create the manifest. It can return anything as long as it's serialisable by `JSO
113
118
114
119
## Hooks Options
115
120
116
- ` filter ` , ` map ` take as an input an Object with the following properties:
121
+ ` filter ` , ` map ` , ` sort ` takes as an input an Object with the following properties:
117
122
118
123
### ` path `
119
124
Original file line number Diff line number Diff line change @@ -136,18 +136,9 @@ ManifestPlugin.prototype.apply = function(compiler) {
136
136
files = files . map ( this . opts . map ) ;
137
137
}
138
138
139
- files = files . sort ( function ( fileA , fileB ) {
140
- var a = fileA . name ;
141
- var b = fileB . name ;
142
-
143
- if ( a < b ) {
144
- return - 1 ;
145
- } else if ( a > b ) {
146
- return 1 ;
147
- } else {
148
- return 0 ;
149
- }
150
- } ) ;
139
+ if ( this . opts . sort ) {
140
+ files = files . sort ( this . opts . sort ) ;
141
+ }
151
142
152
143
var manifest ;
153
144
if ( this . opts . generate ) {
Original file line number Diff line number Diff line change @@ -568,6 +568,36 @@ describe('ManifestPlugin', function() {
568
568
} ) ;
569
569
} ) ;
570
570
571
+ describe ( 'sort' , function ( ) {
572
+ it ( 'should allow ordering of output' , function ( done ) {
573
+ webpackCompile ( {
574
+ context : __dirname ,
575
+ entry : {
576
+ one : './fixtures/file.js' ,
577
+ two : './fixtures/file-two.js'
578
+ } ,
579
+ output : {
580
+ filename : '[name].js'
581
+ }
582
+ } , {
583
+ manifestOptions : {
584
+ seed : [ ] ,
585
+ sort : function ( a , b ) {
586
+ // make sure one is the latest
587
+ return a . name === 'one.js' ? 1 : - 1 ;
588
+ } ,
589
+ generate : function ( seed , files ) {
590
+ return files . map ( file => file . name ) ;
591
+ }
592
+ }
593
+ } , function ( manifest , stats ) {
594
+ expect ( manifest ) . toEqual ( [ 'two.js' , 'one.js' ] ) ;
595
+
596
+ done ( ) ;
597
+ } ) ;
598
+ } ) ;
599
+ } ) ;
600
+
571
601
describe ( 'generate' , function ( ) {
572
602
it ( 'should generate custom manifest' , function ( done ) {
573
603
webpackCompile ( {
You can’t perform that action at this time.
0 commit comments