@@ -21,6 +21,14 @@ function resolveTitle(reportTitle) {
21
21
}
22
22
}
23
23
24
+ function writeToFs ( fs , dest , data ) {
25
+ // older version webpack uses memory-fs whose mkdirSync does not support {recursive: true}
26
+ fs . mkdirpSync
27
+ ? fs . mkdirpSync ( path . dirname ( dest ) )
28
+ : fs . mkdirSync ( path . dirname ( dest ) , { recursive : true } ) ;
29
+ fs . writeFileSync ( dest , data ) ;
30
+ }
31
+
24
32
module . exports = {
25
33
startServer,
26
34
generateReport,
@@ -145,11 +153,7 @@ async function generateReport(bundleStats, opts) {
145
153
} ) ;
146
154
const reportFilepath = path . resolve ( bundleDir || process . cwd ( ) , reportFilename ) ;
147
155
148
- // older version webpack uses memory-fs whose mkdirSync does not support {recursive: true}
149
- fs . mkdirpSync
150
- ? fs . mkdirpSync ( path . dirname ( reportFilepath ) )
151
- : fs . mkdirSync ( path . dirname ( reportFilepath ) , { recursive : true } ) ;
152
- fs . writeFileSync ( reportFilepath , reportHtml ) ;
156
+ writeToFs ( fs , reportFilepath , reportHtml )
153
157
154
158
logger . info ( `${ bold ( 'Webpack Bundle Analyzer' ) } saved report to ${ bold ( reportFilepath ) } ` ) ;
155
159
@@ -165,11 +169,7 @@ async function generateJSONReport(bundleStats, opts) {
165
169
166
170
if ( ! chartData ) return ;
167
171
168
- // older version webpack uses memory-fs whose mkdirSync does not support {recursive: true}
169
- fs . mkdirpSync
170
- ? fs . mkdirpSync ( path . dirname ( reportFilename ) )
171
- : fs . mkdirSync ( path . dirname ( reportFilename ) , { recursive : true } ) ;
172
- fs . writeFileSync ( reportFilename , JSON . stringify ( chartData ) ) ;
172
+ writeToFs ( fs , reportFilename , JSON . stringify ( chartData ) )
173
173
174
174
logger . info ( `${ bold ( 'Webpack Bundle Analyzer' ) } saved JSON report to ${ bold ( reportFilename ) } ` ) ;
175
175
}
0 commit comments