MCPcopy
hub / github.com/tailwindlabs/tailwindcss / generate

Method generate

packages/@tailwindcss-vite/src/index.ts:456–614  ·  view source on GitHub ↗
(
    content: string,
    _addWatchFile: (file: string) => void,
    I: Instrumentation,
  )

Source from the content-addressed store, hash-verified

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

Callers 1

handlerFunction · 0.80

Calls 12

requiresBuildMethod · 0.95
addBuildDependencyMethod · 0.95
clearRequireCacheFunction · 0.90
compileFunction · 0.90
normalizePathFunction · 0.90
toSourceMapFunction · 0.90
idToPathFunction · 0.85
resolveMethod · 0.80
keysMethod · 0.45
startMethod · 0.45
endMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected