@@ -12,42 +12,45 @@ const { mkdirp } = new NodeOutputFileSystem();
12
12
13
13
module . exports = {
14
14
toDisk ( context ) {
15
- context . compiler . hooks . afterEmit . tap ( 'WebpackDevMiddleware' , ( compilation ) => {
16
- const { assets, compiler } = compilation ;
17
- const { log } = context ;
18
- const { writeToDisk : filter } = context . options ;
19
- let { outputPath } = compiler ;
15
+ const compilers = context . compiler . compilers || [ context . compiler ] ;
16
+ for ( const compiler of compilers ) {
17
+ compiler . hooks . afterEmit . tap ( 'WebpackDevMiddleware' , ( compilation ) => {
18
+ const { assets } = compilation ;
19
+ const { log } = context ;
20
+ const { writeToDisk : filter } = context . options ;
21
+ let { outputPath } = compiler ;
20
22
21
- if ( outputPath === '/' ) {
22
- outputPath = compiler . context ;
23
- }
23
+ if ( outputPath === '/' ) {
24
+ outputPath = compiler . context ;
25
+ }
24
26
25
- for ( const assetPath of Object . keys ( assets ) ) {
26
- const asset = assets [ assetPath ] ;
27
- const source = asset . source ( ) ;
28
- const isAbsolute = pathabs ( assetPath ) ;
29
- const writePath = isAbsolute ? assetPath : path . join ( outputPath , assetPath ) ;
30
- const relativePath = path . relative ( process . cwd ( ) , writePath ) ;
31
- const allowWrite = filter && typeof filter === 'function' ? filter ( writePath ) : true ;
27
+ for ( const assetPath of Object . keys ( assets ) ) {
28
+ const asset = assets [ assetPath ] ;
29
+ const source = asset . source ( ) ;
30
+ const isAbsolute = pathabs ( assetPath ) ;
31
+ const writePath = isAbsolute ? assetPath : path . join ( outputPath , assetPath ) ;
32
+ const relativePath = path . relative ( process . cwd ( ) , writePath ) ;
33
+ const allowWrite = filter && typeof filter === 'function' ? filter ( writePath ) : true ;
32
34
33
- if ( allowWrite ) {
34
- let output = source ;
35
+ if ( allowWrite ) {
36
+ let output = source ;
35
37
36
- mkdirp . sync ( path . dirname ( writePath ) ) ;
38
+ mkdirp . sync ( path . dirname ( writePath ) ) ;
37
39
38
- if ( Array . isArray ( source ) ) {
39
- output = source . join ( '\n' ) ;
40
- }
40
+ if ( Array . isArray ( source ) ) {
41
+ output = source . join ( '\n' ) ;
42
+ }
41
43
42
- try {
43
- fs . writeFileSync ( writePath , output , 'utf-8' ) ;
44
- log . debug ( chalk `{cyan Asset written to disk}: ${ relativePath } ` ) ;
45
- } catch ( e ) {
46
- log . error ( `Unable to write asset to disk:\n${ e } ` ) ;
44
+ try {
45
+ fs . writeFileSync ( writePath , output , 'utf-8' ) ;
46
+ log . debug ( chalk `{cyan Asset written to disk}: ${ relativePath } ` ) ;
47
+ } catch ( e ) {
48
+ log . error ( `Unable to write asset to disk:\n${ e } ` ) ;
49
+ }
47
50
}
48
51
}
49
- }
50
- } ) ;
52
+ } ) ;
53
+ }
51
54
} ,
52
55
53
56
setFs ( context , compiler ) {
0 commit comments