@@ -33,40 +33,48 @@ class PlayerLoaderPlugin {
33
33
}
34
34
35
35
apply ( compiler ) {
36
- compiler . hooks . emit . tapAsync ( 'PlayerLoaderPlugin' , ( compilation , callback ) => {
37
- request . get ( this . playerUrl ) . then ( ( playerjs ) => {
38
- let assets = Object . keys ( compilation . assets ) ;
36
+ if ( compiler . hooks && compiler . hooks . emit ) {
37
+ // webpack@4 syntax
38
+ compiler . hooks . emit . tapAsync ( 'PlayerLoaderPlugin' , this . downloadAndAppendPlayer . bind ( this ) ) ;
39
+ } else {
40
+ // webpack@3 syntax
41
+ compiler . plugin ( 'emit' , this . downloadAndAppendPlayer . bind ( this ) ) ;
42
+ }
43
+ }
39
44
40
- // normally we filter out all non .js outputs, and choose prepend to
41
- // only the first output
42
- if ( typeof this . settings_ . prependTo === 'undefined' ) {
43
- // filter out non js files
44
- assets = assets . filter ( ( filename ) => path . extname ( filename ) === '.js' ) ;
45
+ downloadAndAppendPlayer ( compilation , callback ) {
46
+ request . get ( this . playerUrl ) . then ( ( playerjs ) => {
47
+ let assets = Object . keys ( compilation . assets ) ;
45
48
46
- // only prepend to the first one
47
- assets = [ assets [ 0 ] ] ;
49
+ // normally we filter out all non .js outputs, and choose prepend to
50
+ // only the first output
51
+ if ( typeof this . settings_ . prependTo === 'undefined' ) {
52
+ // filter out non js files
53
+ assets = assets . filter ( ( filename ) => path . extname ( filename ) === '.js' ) ;
48
54
49
- // if prependTo is specified though, we prepend to anything that is listed
50
- } else {
51
- assets = assets . filter ( ( filename ) => this . settings_ . prependTo . indexOf ( filename ) === - 1 ) ;
52
- }
55
+ // only prepend to the first one
56
+ assets = [ assets [ 0 ] ] ;
53
57
54
- if ( ! assets . length ) {
55
- console . error ( 'webpack-player-loader-plugin: did not find anything to prepend the player to!' ) ;
56
- console . error ( ) ;
57
- process . exit ( 1 ) ;
58
- }
58
+ // if prependTo is specified though, we prepend to anything that is listed
59
+ } else {
60
+ assets = assets . filter ( ( filename ) => this . settings_ . prependTo . indexOf ( filename ) !== - 1 ) ;
61
+ }
59
62
60
- assets . forEach ( function ( file ) {
61
- compilation . assets [ file ] = new ConcatSource ( playerjs , compilation . assets [ file ] ) ;
62
- } ) ;
63
- callback ( ) ;
64
- } ) . catch ( function ( err ) {
65
- console . error ( 'Failed to get a player at ' + this . playerUrl + ' double check your options' ) ;
66
- console . error ( err ) ;
63
+ if ( ! assets . length ) {
64
+ console . error ( 'webpack-player-loader-plugin: did not find anything to prepend the player to!' ) ;
67
65
console . error ( ) ;
68
66
process . exit ( 1 ) ;
67
+ }
68
+
69
+ assets . forEach ( function ( file ) {
70
+ compilation . assets [ file ] = new ConcatSource ( playerjs , compilation . assets [ file ] ) ;
69
71
} ) ;
72
+ callback ( ) ;
73
+ } ) . catch ( function ( err ) {
74
+ console . error ( 'Failed to get a player at ' + this . playerUrl + ' double check your options' ) ;
75
+ console . error ( err ) ;
76
+ console . error ( ) ;
77
+ process . exit ( 1 ) ;
70
78
} ) ;
71
79
}
72
80
}
0 commit comments