@@ -24,26 +24,36 @@ module.exports = {
24
24
}
25
25
26
26
for ( const assetPath of Object . keys ( assets ) ) {
27
- const asset = assets [ assetPath ] ;
28
- const source = asset . source ( ) ;
29
- const [ assetPathClean ] = assetPath . split ( '?' ) ;
30
- const isAbsolute = path . isAbsolute ( assetPathClean ) ;
31
- const writePath = isAbsolute ? assetPathClean : path . join ( outputPath , assetPathClean ) ;
32
- const relativePath = path . relative ( process . cwd ( ) , writePath ) ;
33
- const allowWrite = filter && typeof filter === 'function' ? filter ( writePath ) : true ;
27
+ let targetFile = assetPath ;
28
+
29
+ const queryStringIdx = targetFile . indexOf ( '?' ) ;
30
+
31
+ if ( queryStringIdx >= 0 ) {
32
+ targetFile = targetFile . substr ( 0 , queryStringIdx ) ;
33
+ }
34
+
35
+ const targetPath = path . isAbsolute ( targetFile ) ? targetFile : path . join ( outputPath , targetFile ) ;
36
+ const allowWrite = filter && typeof filter === 'function' ? filter ( targetPath ) : true ;
34
37
35
38
if ( allowWrite ) {
36
- let output = source ;
39
+ const asset = assets [ assetPath ] ;
40
+ let content = asset . source ( ) ;
37
41
38
- mkdirp . sync ( path . dirname ( writePath ) ) ;
42
+ if ( ! Buffer . isBuffer ( content ) ) {
43
+ // TODO need remove in next major release
44
+ if ( Array . isArray ( content ) ) {
45
+ content = content . join ( '\n' ) ;
46
+ }
39
47
40
- if ( Array . isArray ( source ) ) {
41
- output = source . join ( '\n' ) ;
48
+ content = Buffer . from ( content , 'utf8' ) ;
42
49
}
43
50
51
+ mkdirp . sync ( path . dirname ( targetPath ) ) ;
52
+
44
53
try {
45
- fs . writeFileSync ( writePath , output , 'utf-8' ) ;
46
- log . debug ( colors . cyan ( `Asset written to disk: ${ relativePath } ` ) ) ;
54
+ fs . writeFileSync ( targetPath , content , 'utf-8' ) ;
55
+
56
+ log . debug ( colors . cyan ( `Asset written to disk: ${ path . relative ( process . cwd ( ) , targetPath ) } ` ) ) ;
47
57
} catch ( e ) {
48
58
log . error ( `Unable to write asset to disk:\n${ e } ` ) ;
49
59
}
0 commit comments