@@ -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
@@ -291,7 +277,7 @@ module.exports = function svelte(options = {}) {
291
277
return compiled . js ;
292
278
} ) ;
293
279
} ,
294
- generateBundle ( ) {
280
+ generateBundle ( options , bundle ) {
295
281
if ( css ) {
296
282
// write out CSS file. TODO would be nice if there was a
297
283
// a more idiomatic way to do this in Rollup
@@ -324,11 +310,13 @@ module.exports = function svelte(options = {}) {
324
310
}
325
311
}
326
312
327
- const writer = new CssWriter ( result , {
313
+ const filename = Object . keys ( bundle ) [ 0 ] . split ( '.' ) . slice ( 0 , - 1 ) + '.css' ;
314
+
315
+ const writer = new CssWriter ( result , filename , {
328
316
sources,
329
317
sourcesContent,
330
318
mappings : encode ( mappings )
331
- } , this . warn ) ;
319
+ } , this . warn , this ) ;
332
320
333
321
css ( writer ) ;
334
322
}
0 commit comments