Home / Function/ generate() — tailwindcss Function Reference

generate() — tailwindcss Function Reference

Architecture documentation for the generate() function in index.ts from the tailwindcss codebase.

Function typescript Oxide PreProcessors calls 3 called by 1

Entity Profile

Dependency Diagram

graph TD
  68ac0b75_b7fb_24c9_5ba7_a0d956bcaba5["generate()"]
  26893bc3_0033_d6d7_a323_c3fa650b4ad4["Root"]
  68ac0b75_b7fb_24c9_5ba7_a0d956bcaba5 -->|defined in| 26893bc3_0033_d6d7_a323_c3fa650b4ad4
  3c9d49e5_6033_f167_6ae4_c95f9c17f790["tailwindcss()"]
  3c9d49e5_6033_f167_6ae4_c95f9c17f790 -->|calls| 68ac0b75_b7fb_24c9_5ba7_a0d956bcaba5
  6f92adb6_955a_b157_bc28_eccea87e921f["requiresBuild()"]
  68ac0b75_b7fb_24c9_5ba7_a0d956bcaba5 -->|calls| 6f92adb6_955a_b157_bc28_eccea87e921f
  5162df04_9826_6007_035c_c26fd3cadeca["addBuildDependency()"]
  68ac0b75_b7fb_24c9_5ba7_a0d956bcaba5 -->|calls| 5162df04_9826_6007_035c_c26fd3cadeca
  0d657e77_3379_2516_30ee_b91290d7151d["idToPath()"]
  68ac0b75_b7fb_24c9_5ba7_a0d956bcaba5 -->|calls| 0d657e77_3379_2516_30ee_b91290d7151d
  style 68ac0b75_b7fb_24c9_5ba7_a0d956bcaba5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/@tailwindcss-vite/src/index.ts lines 276–430

  public async generate(
    content: string,
    _addWatchFile: (file: string) => void,
    I: Instrumentation,
  ): Promise<
    | {
        code: string
        map: string | undefined
      }
    | false
  > {
    let inputPath = idToPath(this.id)

    function addWatchFile(file: string) {
      // Don't watch the input file since it's already a dependency and causes
      // issues with some setups (e.g. Qwik).
      if (file === inputPath) {
        return
      }

      // Scanning `.svg` file containing a `#` or `?` in the path will
      // crash Vite. We work around this for now by ignoring updates to them.
      //
      // https://github.com/tailwindlabs/tailwindcss/issues/16877
      if (/[\#\?].*\.svg$/.test(file)) {
        return
      }
      _addWatchFile(file)
    }

    let requiresBuildPromise = this.requiresBuild()
    let inputBase = path.dirname(path.resolve(inputPath))

    if (!this.compiler || !this.scanner || (await requiresBuildPromise)) {
      clearRequireCache(Array.from(this.buildDependencies.keys()))
      this.buildDependencies.clear()

      this.addBuildDependency(idToPath(inputPath))

      DEBUG && I.start('Setup compiler')
      let addBuildDependenciesPromises: Promise<void>[] = []
      this.compiler = await compile(content, {
        from: this.enableSourceMaps ? this.id : undefined,
        base: inputBase,
        shouldRewriteUrls: true,
        onDependency: (path) => {
          addWatchFile(path)
          addBuildDependenciesPromises.push(this.addBuildDependency(path))
        },

        customCssResolver: this.customCssResolver,
        customJsResolver: this.customJsResolver,
      })
      await Promise.all(addBuildDependenciesPromises)
      DEBUG && I.end('Setup compiler')

      DEBUG && I.start('Setup scanner')

      let sources = (() => {
        // Disable auto source detection
        if (this.compiler.root === 'none') {
          return []
        }

        // No root specified, auto-detect based on the `**/*` pattern
        if (this.compiler.root === null) {
          return [{ base: this.base, pattern: '**/*', negated: false }]
        }

        // Use the specified root
        return [{ ...this.compiler.root, negated: false }]
      })().concat(this.compiler.sources)

      this.scanner = new Scanner({ sources })
      DEBUG && I.end('Setup scanner')
    } else {
      for (let buildDependency of this.buildDependencies.keys()) {
        addWatchFile(buildDependency)
      }
    }

Domain

Subdomains

Called By

Frequently Asked Questions

What does generate() do?
generate() is a function in the tailwindcss codebase, defined in packages/@tailwindcss-vite/src/index.ts.
Where is generate() defined?
generate() is defined in packages/@tailwindcss-vite/src/index.ts at line 276.
What does generate() call?
generate() calls 3 function(s): addBuildDependency, idToPath, requiresBuild.
What calls generate()?
generate() is called by 1 function(s): tailwindcss.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free