Home / Function/ generate() — tailwindcss Function Reference

generate() — tailwindcss Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  b67e45c0_c12e_4110_8571_4aae09401670["generate()"]
  83ec979e_3b39_d4e7_8258_76d6f894ddf7["Root"]
  b67e45c0_c12e_4110_8571_4aae09401670 -->|defined in| 83ec979e_3b39_d4e7_8258_76d6f894ddf7
  b3c6ca19_5b31_3c72_53a9_de53e821f992["tailwindcss()"]
  b3c6ca19_5b31_3c72_53a9_de53e821f992 -->|calls| b67e45c0_c12e_4110_8571_4aae09401670
  f882fe51_12ba_0eae_b8af_ca3a42cb72a8["requiresBuild()"]
  b67e45c0_c12e_4110_8571_4aae09401670 -->|calls| f882fe51_12ba_0eae_b8af_ca3a42cb72a8
  a5d72d57_d23e_d4a0_790b_7872da6c34d1["addBuildDependency()"]
  b67e45c0_c12e_4110_8571_4aae09401670 -->|calls| a5d72d57_d23e_d4a0_790b_7872da6c34d1
  bcfe6299_a924_4a87_dea8_c990af089fdd["idToPath()"]
  b67e45c0_c12e_4110_8571_4aae09401670 -->|calls| bcfe6299_a924_4a87_dea8_c990af089fdd
  style b67e45c0_c12e_4110_8571_4aae09401670 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)
      }
    }

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