@@ -16,29 +16,6 @@ console.warn(
1616 */
1717let compiler : Awaited < ReturnType < typeof tailwindcss . compile > >
1818
19- /**
20- * The list of all seen classes on the page so far. The compiler already has a
21- * cache of classes but this lets us only pass new classes to `build(…)`.
22- */
23- let classes = new Set < string > ( )
24-
25- /**
26- * The last input CSS that was compiled. If stylesheets "change" without
27- * actually changing, we can avoid a full rebuild.
28- */
29- let lastCss = ''
30-
31-
32- /**
33- * The queue of build tasks that need to be run. This is used to ensure that we
34- * don't run multiple builds concurrently.
35- */
36- let buildQueue = Promise . resolve < string > ( '' )
37-
38- /**
39- * What build this is
40- */
41- let nextBuildId = 1
4219
4320/**
4421 * Used for instrumenting the build process. This data shows up in the
@@ -54,28 +31,11 @@ let I = new Instrumentation()
5431 * This does **not** imply that the CSS is actually built. That happens in the
5532 * `build` function and is a separate scheduled task.
5633 */
57- async function createCompiler ( css : string ) {
34+ async function createCompiler ( ) {
5835 I . start ( `Create compiler` )
5936 I . start ( 'Reading Stylesheets' )
6037
61-
62- // The user might have no stylesheets, or a some stylesheets without `@import`
63- // because they want to customize their theme so we'll inject the main import
64- // for them. However, if they start using `@import` we'll let them control
65- // the build completely.
66- if ( ! css . includes ( '@import' ) ) {
67- css = `@import "tailwindcss";${ css } `
68- }
69-
70- I . end ( 'Reading Stylesheets' , {
71- size : css . length ,
72- changed : lastCss !== css ,
73- } )
74-
75- // The input CSS did not change so the compiler does not need to be recreated
76- if ( lastCss === css ) return
77-
78- lastCss = css
38+ const css = `@import "tailwindcss";`
7939
8040 I . start ( 'Compile CSS' )
8141 try {
@@ -88,8 +48,6 @@ async function createCompiler(css: string) {
8848 I . end ( 'Compile CSS' )
8949 I . end ( `Create compiler` )
9050 }
91-
92- classes . clear ( )
9351}
9452
9553async function loadStylesheet ( id : string , base : string ) {
@@ -160,59 +118,25 @@ async function loadModule(): Promise<never> {
160118 throw new Error ( `The browser build does not support plugins or config files.` )
161119}
162120
163- async function build ( ) {
164- if ( ! compiler ) return
165121
166- // 1. Refresh the known list of classes
167- let newClasses = new Set < string > ( )
168-
169- I . start ( `Collect classes` )
170-
171- for ( let element of document . querySelectorAll ( '[class]' ) ) {
172- for ( let c of element . classList ) {
173- if ( classes . has ( c ) ) continue
174-
175- classes . add ( c )
176- newClasses . add ( c )
177- }
178- }
179-
180- I . end ( `Collect classes` , {
181- count : newClasses . size ,
182- } )
183-
184- // 2. Compile the CSS
185- I . start ( `Build utilities` )
186-
187- const result = compiler . build ( Array . from ( newClasses ) )
188-
189- I . end ( `Build utilities` )
190-
191- return result ;
192- }
193-
194- async function rebuild ( css : string ) {
122+ async function rebuild ( classes : Set < string > ) {
195123 async function run ( ) {
196124
197- let buildId = nextBuildId ++
198-
199- I . start ( `Build #${ buildId } ` )
200-
201- await createCompiler ( css )
202-
125+ if ( ! compiler ) {
126+ await createCompiler ( )
127+ }
203128
204129 I . start ( `Build` )
205- const result = await build ( ) ;
130+ const result = compiler . build ( Array . from ( classes ) )
206131 I . end ( `Build` )
207132
208- I . end ( `Build # ${ buildId } ` )
133+ I . end ( `Build` )
209134
210135 return result ?? '' ;
211136 }
212137
213138 try {
214- buildQueue = buildQueue . then ( run ) ;
215- return await buildQueue ;
139+ return await Promise . resolve ( ) . then ( run ) ; ;
216140 } catch ( error ) {
217141 I . error ( error ) ;
218142 }
0 commit comments