@@ -141,6 +141,9 @@ module.exports = function svelte(options = {}) {
141
141
? options . css
142
142
: null ;
143
143
144
+ // A map from css filename to css contents
145
+ // If css: true we output all contents
146
+ // If emitCss: true we virtually resolve these imports
144
147
const cssLookup = new Map ( ) ;
145
148
146
149
if ( css || options . emitCss ) {
@@ -150,11 +153,17 @@ module.exports = function svelte(options = {}) {
150
153
return {
151
154
name : 'svelte' ,
152
155
156
+ /**
157
+ * Returns CSS contents for an id
158
+ */
153
159
load ( id ) {
154
160
if ( ! cssLookup . has ( id ) ) return null ;
155
161
return cssLookup . get ( id ) ;
156
162
} ,
157
163
164
+ /**
165
+ * Returns id for import
166
+ */
158
167
resolveId ( importee , importer ) {
159
168
if ( cssLookup . has ( importee ) ) { return importee ; }
160
169
if ( ! importer || importee [ 0 ] === '.' || importee [ 0 ] === '\0' || path . isAbsolute ( importee ) )
@@ -189,6 +198,10 @@ module.exports = function svelte(options = {}) {
189
198
}
190
199
} ,
191
200
201
+ /**
202
+ * Transforms a .svelte file into a .js file
203
+ * Adds a static import for virtual css file when emitCss: true
204
+ */
192
205
transform ( code , id ) {
193
206
if ( ! filter ( id ) ) return null ;
194
207
@@ -283,10 +296,12 @@ module.exports = function svelte(options = {}) {
283
296
return compiled . js ;
284
297
} ) ;
285
298
} ,
299
+ /**
300
+ * If css: true then outputs a single file with all CSS bundled together
301
+ */
286
302
generateBundle ( options , bundle ) {
287
303
if ( css ) {
288
- // write out CSS file. TODO would be nice if there was a
289
- // a more idiomatic way to do this in Rollup
304
+ // TODO would be nice if there was a more idiomatic way to do this in Rollup
290
305
let result = '' ;
291
306
292
307
const mappings = [ ] ;
0 commit comments