tailwindcss() — tailwindcss Function Reference
Architecture documentation for the tailwindcss() function in index.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 7e4891ad_b5c5_f083_e9e1_3dc43422517d["tailwindcss()"] 4d87ade3_79e3_f749_8b40_7a0e8f43b9dc["index.ts"] 7e4891ad_b5c5_f083_e9e1_3dc43422517d -->|defined in| 4d87ade3_79e3_f749_8b40_7a0e8f43b9dc 06a6b835_65ff_54fa_2194_b15613c95964["fixRelativePathsPlugin()"] 7e4891ad_b5c5_f083_e9e1_3dc43422517d -->|calls| 06a6b835_65ff_54fa_2194_b15613c95964 53f8c5ca_9d70_37ce_3501_1b2ac9315393["getContextFromCache()"] 7e4891ad_b5c5_f083_e9e1_3dc43422517d -->|calls| 53f8c5ca_9d70_37ce_3501_1b2ac9315393 117741fb_51f9_63e4_669e_170efd25ca86["postCssAstToCssAst()"] 7e4891ad_b5c5_f083_e9e1_3dc43422517d -->|calls| 117741fb_51f9_63e4_669e_170efd25ca86 2da63033_d079_7b37_5cfb_3877674a70b9["toCss()"] 7e4891ad_b5c5_f083_e9e1_3dc43422517d -->|calls| 2da63033_d079_7b37_5cfb_3877674a70b9 2b13c224_9fb8_311a_1669_17e838226ea5["cssAstToPostCssAst()"] 7e4891ad_b5c5_f083_e9e1_3dc43422517d -->|calls| 2b13c224_9fb8_311a_1669_17e838226ea5 style 7e4891ad_b5c5_f083_e9e1_3dc43422517d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/@tailwindcss-postcss/src/index.ts lines 71–363
function tailwindcss(opts: PluginOptions = {}): AcceptedPlugin {
let base = opts.base ?? process.cwd()
let optimize = opts.optimize ?? process.env.NODE_ENV === 'production'
let shouldRewriteUrls = opts.transformAssetUrls ?? true
return {
postcssPlugin: '@tailwindcss/postcss',
plugins: [
// We need to handle the case where `postcss-import` might have run before
// the Tailwind CSS plugin is run. In this case, we need to manually fix
// relative paths before processing it in core.
fixRelativePathsPlugin(),
{
postcssPlugin: 'tailwindcss',
async Once(root, { result, postcss }) {
using I = new Instrumentation()
let inputFile = result.opts.from ?? ''
let isCSSModuleFile = inputFile.endsWith('.module.css')
DEBUG && I.start(`[@tailwindcss/postcss] ${relative(base, inputFile)}`)
// Bail out early if this is guaranteed to be a non-Tailwind CSS file.
{
DEBUG && I.start('Quick bail check')
let canBail = true
root.walkAtRules((node) => {
if (
node.name === 'import' ||
node.name === 'reference' ||
node.name === 'theme' ||
node.name === 'variant' ||
node.name === 'config' ||
node.name === 'plugin' ||
node.name === 'apply' ||
node.name === 'tailwind'
) {
canBail = false
return false
}
})
if (canBail) return
DEBUG && I.end('Quick bail check')
}
let context = getContextFromCache(postcss, inputFile, opts)
let inputBasePath = path.dirname(path.resolve(inputFile))
// Whether this is the first build or not, if it is, then we can
// optimize the build by not creating the compiler until we need it.
let isInitialBuild = context.compiler === null
async function createCompiler() {
DEBUG && I.start('Setup compiler')
if (context.fullRebuildPaths.length > 0 && !isInitialBuild) {
clearRequireCache(context.fullRebuildPaths)
}
context.fullRebuildPaths = []
DEBUG && I.start('PostCSS AST -> Tailwind CSS AST')
let ast = postCssAstToCssAst(root)
DEBUG && I.end('PostCSS AST -> Tailwind CSS AST')
DEBUG && I.start('Create compiler')
let compiler = await compileAst(ast, {
from: result.opts.from,
base: inputBasePath,
shouldRewriteUrls,
onDependency: (path) => context.fullRebuildPaths.push(path),
// In CSS Module files, we have to disable the `@property` polyfill since these will
// emit global `*` rules which are considered to be non-pure and will cause builds
// to fail.
polyfills: isCSSModuleFile ? Polyfills.All ^ Polyfills.AtProperty : Polyfills.All,
})
DEBUG && I.end('Create compiler')
DEBUG && I.end('Setup compiler')
return compiler
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does tailwindcss() do?
tailwindcss() is a function in the tailwindcss codebase, defined in packages/@tailwindcss-postcss/src/index.ts.
Where is tailwindcss() defined?
tailwindcss() is defined in packages/@tailwindcss-postcss/src/index.ts at line 71.
What does tailwindcss() call?
tailwindcss() calls 5 function(s): cssAstToPostCssAst, fixRelativePathsPlugin, getContextFromCache, postCssAstToCssAst, toCss.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free