@@ -17,81 +17,59 @@ class CopyPlugin {
17
17
}
18
18
19
19
apply ( compiler ) {
20
- const fileDependencies = new Set ( ) ;
21
- const contextDependencies = new Set ( ) ;
22
20
const plugin = { name : 'CopyPlugin' } ;
23
- const logger = compiler . getInfrastructureLogger ( 'copy-webpack-plugin' ) ;
24
21
25
- compiler . hooks . emit . tapAsync ( plugin , ( compilation , callback ) => {
26
- logger . debug ( 'starting emit ') ;
22
+ compiler . hooks . compilation . tap ( plugin , ( compilation ) => {
23
+ const logger = compilation . getLogger ( 'copy-webpack-plugin ') ;
27
24
28
- const globalRef = {
29
- context : compiler . options . context ,
30
- logger,
31
- compilation,
32
- fileDependencies,
33
- contextDependencies,
34
- inputFileSystem : compiler . inputFileSystem ,
35
- output : compiler . options . output . path ,
36
- ignore : this . options . ignore || [ ] ,
37
- concurrency : this . options . concurrency ,
38
- } ;
25
+ compilation . hooks . additionalAssets . tapAsync (
26
+ 'copy-webpack-plugin' ,
27
+ ( callback ) => {
28
+ logger . debug ( 'start to adding additionalAssets' ) ;
39
29
40
- Promise . all (
41
- this . patterns . map ( ( pattern ) =>
42
- Promise . resolve ( )
43
- . then ( ( ) => preProcessPattern ( globalRef , pattern ) )
44
- // Every source (from) is assumed to exist here
45
- // eslint-disable-next-line no-shadow
46
- . then ( ( pattern ) =>
47
- processPattern ( globalRef , pattern ) . then ( ( files ) => {
48
- if ( ! files ) {
49
- return Promise . resolve ( ) ;
50
- }
30
+ const globalRef = {
31
+ context : compiler . options . context ,
32
+ logger,
33
+ compilation,
34
+ inputFileSystem : compiler . inputFileSystem ,
35
+ output : compiler . options . output . path ,
36
+ ignore : this . options . ignore || [ ] ,
37
+ concurrency : this . options . concurrency ,
38
+ } ;
51
39
52
- return Promise . all (
53
- files
54
- . filter ( Boolean )
55
- . map ( ( file ) => postProcessPattern ( globalRef , pattern , file ) )
56
- ) ;
57
- } )
58
- )
59
- )
60
- )
61
- . catch ( ( error ) => {
62
- compilation . errors . push ( error ) ;
63
- } )
64
- . then ( ( ) => {
65
- logger . debug ( 'finishing emit' ) ;
66
-
67
- callback ( ) ;
68
- } ) ;
69
- } ) ;
70
-
71
- compiler . hooks . afterEmit . tapAsync ( plugin , ( compilation , callback ) => {
72
- logger . debug ( 'starting after-emit' ) ;
40
+ Promise . all (
41
+ this . patterns . map ( ( pattern ) =>
42
+ Promise . resolve ( )
43
+ . then ( ( ) => preProcessPattern ( globalRef , pattern ) )
44
+ // Every source (from) is assumed to exist here
45
+ // eslint-disable-next-line no-shadow
46
+ . then ( ( pattern ) =>
47
+ processPattern ( globalRef , pattern ) . then ( ( files ) => {
48
+ if ( ! files ) {
49
+ return Promise . resolve ( ) ;
50
+ }
73
51
74
- // Add file dependencies
75
- if ( 'addAll' in compilation . fileDependencies ) {
76
- compilation . fileDependencies . addAll ( fileDependencies ) ;
77
- } else {
78
- for ( const fileDependency of fileDependencies ) {
79
- compilation . fileDependencies . add ( fileDependency ) ;
80
- }
81
- }
52
+ return Promise . all (
53
+ files
54
+ . filter ( Boolean )
55
+ . map ( ( file ) =>
56
+ postProcessPattern ( globalRef , pattern , file )
57
+ )
58
+ ) ;
59
+ } )
60
+ )
61
+ )
62
+ )
63
+ . catch ( ( error ) => {
64
+ compilation . errors . push ( error ) ;
65
+ } )
66
+ . then ( ( ) => {
67
+ logger . debug ( 'end to adding additionalAssets' ) ;
82
68
83
- // Add context dependencies
84
- if ( 'addAll' in compilation . contextDependencies ) {
85
- compilation . contextDependencies . addAll ( contextDependencies ) ;
86
- } else {
87
- for ( const contextDependency of contextDependencies ) {
88
- compilation . contextDependencies . add ( contextDependency ) ;
69
+ callback ( ) ;
70
+ } ) ;
89
71
}
90
- }
91
-
92
- logger . debug ( 'finishing after-emit' ) ;
93
-
94
- callback ( ) ;
72
+ ) ;
95
73
} ) ;
96
74
}
97
75
}
0 commit comments