Skip to content

Commit a8a6040

Browse files
authored
Load v3/v4 modules only when needed (#439)
1 parent ecdf567 commit a8a6040

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/sorter.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { resolveJsFrom } from './resolve'
77
import { sortClasses, sortClassList } from './sorting.js'
88
import type { TransformerEnv, UnifiedApi } from './types'
99
import { cacheForDirs } from './utils.js'
10-
import { loadV3 } from './versions/v3'
11-
import { loadV4 } from './versions/v4'
1210

1311
export interface SorterOptions {
1412
/**
@@ -158,7 +156,10 @@ export async function getTailwindConfig(options: TailwindConfigOptions): Promise
158156
// or because it was automatically located. This means we should use v3.
159157
if (jsConfig) {
160158
if (!stylesheet) {
161-
return pathToApiMap.remember(`${pkgDir}:${jsConfig}`, () => loadV3(pkgDir, jsConfig))
159+
return pathToApiMap.remember(`${pkgDir}:${jsConfig}`, async () => {
160+
const { loadV3 } = await import('./versions/v3')
161+
return loadV3(pkgDir, jsConfig)
162+
})
162163
}
163164

164165
// In this case the user explicitly gave us a stylesheet and a config.
@@ -172,7 +173,10 @@ export async function getTailwindConfig(options: TailwindConfigOptions): Promise
172173

173174
if (mod && !mod.__unstable__loadDesignSystem) {
174175
if (!stylesheet) {
175-
return pathToApiMap.remember(`${pkgDir}:${jsConfig}`, () => loadV3(pkgDir, jsConfig))
176+
return pathToApiMap.remember(`${pkgDir}:${jsConfig}`, async () => {
177+
const { loadV3 } = await import('./versions/v3')
178+
return loadV3(pkgDir, jsConfig)
179+
})
176180
}
177181

178182
// In this case the user explicitly gave us a stylesheet but their local
@@ -191,7 +195,10 @@ export async function getTailwindConfig(options: TailwindConfigOptions): Promise
191195
stylesheet ??= `${pkgDir}/theme.css`
192196
}
193197

194-
return pathToApiMap.remember(`${pkgDir}:${stylesheet}`, () => loadV4(mod, stylesheet))
198+
return pathToApiMap.remember(`${pkgDir}:${stylesheet}`, async () => {
199+
const { loadV4 } = await import('./versions/v4')
200+
return loadV4(mod, stylesheet)
201+
})
195202
}
196203

197204
let resolvedModCache = expiringMap<string, [any | null, string | null]>(10_000)

0 commit comments

Comments
 (0)