@@ -100,6 +100,8 @@ const ABORT = { aborted: true };
100
100
let previous : {
101
101
key : string ;
102
102
cache : RollupCache | undefined ;
103
+ /** Needed because if rollup cache hits then we won't be able to pick up all candidates in subsequent runs */
104
+ tailwind_candidates : Set < string > ;
103
105
} ;
104
106
105
107
let tailwind : Awaited < ReturnType < typeof init_tailwind > > ;
@@ -143,12 +145,14 @@ async function get_bundle(
143
145
) {
144
146
let bundle ;
145
147
148
+ const key = JSON . stringify ( options ) ;
146
149
/** A set of package names (without subpaths) to include in pkg.devDependencies when downloading an app */
147
150
const imports : Set < string > = new Set ( ) ;
148
151
const warnings : Warning [ ] = [ ] ;
149
152
const all_warnings : Array < { message : string } > = [ ] ;
150
153
151
- const tailwind_candidates : string [ ] = [ ] ;
154
+ const tailwind_candidates =
155
+ previous ?. key === key ? previous . tailwind_candidates : new Set < string > ( ) ;
152
156
153
157
function add_tailwind_candidates ( ast : Node | undefined ) {
154
158
if ( ! ast ) return ;
@@ -160,12 +164,16 @@ async function get_bundle(
160
164
} ,
161
165
Literal ( node ) {
162
166
if ( typeof node . value === 'string' && node . value ) {
163
- tailwind_candidates . push ( ...node . value . split ( ' ' ) ) ;
167
+ for ( const candidate of node . value . split ( ' ' ) ) {
168
+ if ( candidate ) tailwind_candidates . add ( candidate ) ;
169
+ }
164
170
}
165
171
} ,
166
172
TemplateElement ( node ) {
167
173
if ( node . value . raw ) {
168
- tailwind_candidates . push ( ...node . value . raw . split ( ' ' ) ) ;
174
+ for ( const candidate of node . value . raw . split ( ' ' ) ) {
175
+ if ( candidate ) tailwind_candidates . add ( candidate ) ;
176
+ }
169
177
}
170
178
}
171
179
} ) ;
@@ -283,20 +291,19 @@ async function get_bundle(
283
291
transform ( code , id ) {
284
292
if ( uid !== current_id ) throw ABORT ;
285
293
286
- const message = `bundling ${ id . replace ( VIRTUAL + '/' , '' ) . replace ( NPM + '/' , '' ) } ` ;
287
- self . postMessage ( { type : 'status' , message } ) ;
294
+ const name = id . replace ( VIRTUAL + '/' , '' ) . replace ( NPM + '/' , '' ) ;
288
295
289
- if ( ! / \. ( s v e l t e | j s | t s ) $ / . test ( id ) ) return null ;
296
+ self . postMessage ( { type : 'status' , message : `bundling ${ name } ` } ) ;
290
297
291
- const name = id . split ( '/' ) . pop ( ) ?. split ( '.' ) [ 0 ] ;
298
+ if ( ! / \. ( s v e l t e | j s | t s ) $ / . test ( id ) ) return null ;
292
299
293
300
let result : CompileResult ;
294
301
295
302
if ( id . endsWith ( '.svelte' ) ) {
296
303
const is_gt_5 = Number ( svelte . VERSION . split ( '.' ) [ 0 ] ) >= 5 ;
297
304
298
305
const compilerOptions : any = {
299
- filename : name + '.svelte' ,
306
+ filename : name ,
300
307
generate : is_gt_5 ? 'client' : 'dom' ,
301
308
dev : true ,
302
309
fragments : options . fragments
@@ -323,7 +330,9 @@ async function get_bundle(
323
330
if ( Array . isArray ( node . value ) ) {
324
331
for ( const chunk of node . value ) {
325
332
if ( chunk . type === 'Text' ) {
326
- tailwind_candidates . push ( ...chunk . data . split ( ' ' ) ) ;
333
+ for ( const candidate of chunk . data . split ( ' ' ) ) {
334
+ if ( candidate ) tailwind_candidates . add ( candidate ) ;
335
+ }
327
336
}
328
337
}
329
338
}
@@ -363,7 +372,7 @@ async function get_bundle(
363
372
}
364
373
} else if ( / \. s v e l t e \. ( j s | t s ) $ / . test ( id ) ) {
365
374
const compilerOptions : any = {
366
- filename : name + '.js' ,
375
+ filename : name ,
367
376
generate : 'client' ,
368
377
dev : true
369
378
} ;
@@ -400,13 +409,12 @@ async function get_bundle(
400
409
}
401
410
} ;
402
411
403
- const key = JSON . stringify ( options ) ;
404
412
const handled_css_ids = new Set < string > ( ) ;
405
413
let user_css = '' ;
406
414
407
415
bundle = await rollup ( {
408
416
input : './__entry.js' ,
409
- cache : previous ?. key === key && previous . cache ,
417
+ cache : previous ?. key === key ? previous . cache : true ,
410
418
plugins : [
411
419
alias_plugin ( options . aliases , virtual ) ,
412
420
typescript_strip_types ,
@@ -460,12 +468,12 @@ async function get_bundle(
460
468
}
461
469
} ) ;
462
470
463
- previous = { key, cache : bundle . cache } ;
471
+ previous = { key, cache : bundle . cache , tailwind_candidates } ;
464
472
465
473
return {
466
474
bundle,
467
475
css : options . tailwind
468
- ? ( tailwind ?? ( await init_tailwind ( user_css ) ) ) . build ( tailwind_candidates )
476
+ ? ( tailwind ?? ( await init_tailwind ( user_css ) ) ) . build ( [ ... tailwind_candidates ] )
469
477
: user_css
470
478
? user_css
471
479
: null ,
0 commit comments