@@ -64,22 +64,10 @@ function exists(file) {
64
64
}
65
65
}
66
66
67
- function mkdirp ( dir ) {
68
- const parent = path . dirname ( dir ) ;
69
- if ( parent === dir ) return ;
70
-
71
- mkdirp ( parent ) ;
72
-
73
- try {
74
- fs . mkdirSync ( dir ) ;
75
- } catch ( err ) {
76
- if ( err . code !== 'EEXIST' ) throw err ;
77
- }
78
- }
79
-
80
67
class CssWriter {
81
- constructor ( code , map , warn ) {
68
+ constructor ( code , filename , map , warn , bundle ) {
82
69
this . code = code ;
70
+ this . filename = filename ;
83
71
this . map = {
84
72
version : 3 ,
85
73
file : null ,
@@ -89,26 +77,24 @@ class CssWriter {
89
77
mappings : map . mappings
90
78
} ;
91
79
this . warn = warn ;
80
+ this . bundle = bundle ;
92
81
}
93
82
94
- write ( dest , map ) {
95
- dest = path . resolve ( dest ) ;
96
- mkdirp ( path . dirname ( dest ) ) ;
97
-
83
+ write ( dest = this . filename , map ) {
98
84
const basename = path . basename ( dest ) ;
99
85
100
86
if ( map !== false ) {
101
- fs . writeFileSync ( dest , `${ this . code } \n/*# sourceMappingURL=${ basename } .map */` ) ;
102
- fs . writeFileSync ( `${ dest } .map` , JSON . stringify ( {
87
+ this . bundle . emitFile ( { type : 'asset' , fileName : dest , source : `${ this . code } \n/*# sourceMappingURL=${ basename } .map */` } ) ;
88
+ this . bundle . emitFile ( { type : 'asset' , fileName : `${ dest } .map` , source : JSON . stringify ( {
103
89
version : 3 ,
104
90
file : basename ,
105
91
sources : this . map . sources . map ( source => path . relative ( path . dirname ( dest ) , source ) ) ,
106
92
sourcesContent : this . map . sourcesContent ,
107
93
names : [ ] ,
108
94
mappings : this . map . mappings
109
- } , null , ' ' ) ) ;
95
+ } , null , ' ' ) } ) ;
110
96
} else {
111
- fs . writeFileSync ( dest , this . code ) ;
97
+ this . bundle . emitFile ( { type : 'asset' , fileName : dest , source : this . code } ) ;
112
98
}
113
99
}
114
100
@@ -292,7 +278,7 @@ module.exports = function svelte(options = {}) {
292
278
return compiled . js ;
293
279
} ) ;
294
280
} ,
295
- generateBundle ( ) {
281
+ generateBundle ( options , bundle ) {
296
282
if ( css ) {
297
283
// write out CSS file. TODO would be nice if there was a
298
284
// a more idiomatic way to do this in Rollup
@@ -327,11 +313,13 @@ module.exports = function svelte(options = {}) {
327
313
}
328
314
}
329
315
330
- const writer = new CssWriter ( result , {
316
+ const filename = Object . keys ( bundle ) [ 0 ] . split ( '.' ) . shift ( ) + '.css' ;
317
+
318
+ const writer = new CssWriter ( result , filename , {
331
319
sources,
332
320
sourcesContent,
333
321
mappings : encode ( mappings )
334
- } , this . warn ) ;
322
+ } , this . warn , this ) ;
335
323
336
324
css ( writer ) ;
337
325
}
0 commit comments