@@ -6,6 +6,7 @@ const Logger = require('./Logger');
6
6
const viewer = require ( './viewer' ) ;
7
7
const utils = require ( './utils' ) ;
8
8
const { writeStats} = require ( './statsUtils' ) ;
9
+ const PLUGIN_NAME = 'webpack-bundle-analyzer' ;
9
10
10
11
class BundleAnalyzerPlugin {
11
12
constructor ( opts = { } ) {
@@ -28,13 +29,15 @@ class BundleAnalyzerPlugin {
28
29
} ;
29
30
30
31
this . server = null ;
31
- this . logger = new Logger ( this . opts . logLevel ) ;
32
32
}
33
33
34
34
apply ( compiler ) {
35
35
this . compiler = compiler ;
36
36
37
+ this . logger = compiler ?. getInfrastructureLogger ( PLUGIN_NAME ) || require ( 'webpack/logging/runtime' ) . getLogger ( PLUGIN_NAME ) ;
38
+
37
39
const done = ( stats , callback ) => {
40
+ this . fs = compiler . outputFileSystem ;
38
41
callback = callback || ( ( ) => { } ) ;
39
42
40
43
const actions = [ ] ;
@@ -72,15 +75,15 @@ class BundleAnalyzerPlugin {
72
75
} ;
73
76
74
77
if ( compiler . hooks ) {
75
- compiler . hooks . done . tapAsync ( 'webpack-bundle-analyzer' , done ) ;
78
+ compiler . hooks . done . tapAsync ( PLUGIN_NAME , done ) ;
76
79
} else {
77
80
compiler . plugin ( 'done' , done ) ;
78
81
}
79
82
}
80
83
81
84
async generateStatsFile ( stats ) {
82
85
const statsFilepath = path . resolve ( this . compiler . outputPath , this . opts . statsFilename ) ;
83
- await fs . promises . mkdir ( path . dirname ( statsFilepath ) , { recursive : true } ) ;
86
+ await this . fs . promises . mkdir ( path . dirname ( statsFilepath ) , { recursive : true } ) ;
84
87
85
88
try {
86
89
await writeStats ( stats , statsFilepath ) ;
@@ -117,7 +120,8 @@ class BundleAnalyzerPlugin {
117
120
reportFilename : path . resolve ( this . compiler . outputPath , this . opts . reportFilename || 'report.json' ) ,
118
121
bundleDir : this . getBundleDirFromCompiler ( ) ,
119
122
logger : this . logger ,
120
- excludeAssets : this . opts . excludeAssets
123
+ excludeAssets : this . opts . excludeAssets ,
124
+ fs : this . fs
121
125
} ) ;
122
126
}
123
127
@@ -129,7 +133,8 @@ class BundleAnalyzerPlugin {
129
133
bundleDir : this . getBundleDirFromCompiler ( ) ,
130
134
logger : this . logger ,
131
135
defaultSizes : this . opts . defaultSizes ,
132
- excludeAssets : this . opts . excludeAssets
136
+ excludeAssets : this . opts . excludeAssets ,
137
+ fs : this . fs
133
138
} ) ;
134
139
}
135
140
0 commit comments