(
content: string,
_addWatchFile: (file: string) => void,
I: Instrumentation,
)
| 454 | // Generate the CSS for the root file. This can return false if the file is |
| 455 | // not considered a Tailwind root. When this happened, the root can be GCed. |
| 456 | public async generate( |
| 457 | content: string, |
| 458 | _addWatchFile: (file: string) => void, |
| 459 | I: Instrumentation, |
| 460 | ): Promise< |
| 461 | | { |
| 462 | code: string |
| 463 | map: string | undefined |
| 464 | } |
| 465 | | false |
| 466 | > { |
| 467 | let inputPath = idToPath(this.id) |
| 468 | |
| 469 | function addWatchFile(file: string) { |
| 470 | // Don't watch the input file since it's already a dependency and causes |
| 471 | // issues with some setups (e.g. Qwik). |
| 472 | if (file === inputPath) { |
| 473 | return |
| 474 | } |
| 475 | |
| 476 | // Scanning `.svg` file containing a `#` or `?` in the path will |
| 477 | // crash Vite. We work around this for now by ignoring updates to them. |
| 478 | // |
| 479 | // https://github.com/tailwindlabs/tailwindcss/issues/16877 |
| 480 | if (/[#?].*\.svg$/.test(file)) { |
| 481 | return |
| 482 | } |
| 483 | _addWatchFile(file) |
| 484 | } |
| 485 | |
| 486 | let requiresBuildPromise = this.requiresBuild() |
| 487 | let inputBase = path.dirname(path.resolve(inputPath)) |
| 488 | |
| 489 | if (!this.compiler || !this.scanner || (await requiresBuildPromise)) { |
| 490 | clearRequireCache(Array.from(this.buildDependencies.keys())) |
| 491 | this.buildDependencies.clear() |
| 492 | |
| 493 | this.addBuildDependency(idToPath(inputPath)) |
| 494 | |
| 495 | DEBUG && I.start('Setup compiler') |
| 496 | let addBuildDependenciesPromises: Promise<void>[] = [] |
| 497 | this.compiler = await compile(content, { |
| 498 | from: this.enableSourceMaps ? this.id : undefined, |
| 499 | base: inputBase, |
| 500 | shouldRewriteUrls: true, |
| 501 | onDependency: (path) => { |
| 502 | addWatchFile(path) |
| 503 | addBuildDependenciesPromises.push(this.addBuildDependency(path)) |
| 504 | }, |
| 505 | |
| 506 | customCssResolver: this.customCssResolver, |
| 507 | customJsResolver: this.customJsResolver, |
| 508 | }) |
| 509 | await Promise.all(addBuildDependenciesPromises) |
| 510 | DEBUG && I.end('Setup compiler') |
| 511 | |
| 512 | DEBUG && I.start('Setup scanner') |
| 513 |
no test coverage detected