tailwindLoader() — tailwindcss Function Reference
Architecture documentation for the tailwindLoader() function in index.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 7819558a_2ee5_2bed_63fd_99f25ef02d0f["tailwindLoader()"] b294614b_1806_4c31_9786_09a2dbe0d909["index.ts"] 7819558a_2ee5_2bed_63fd_99f25ef02d0f -->|defined in| b294614b_1806_4c31_9786_09a2dbe0d909 aedb31dd_2729_9802_8cc8_22b3c31651b5["getContextFromCache()"] 7819558a_2ee5_2bed_63fd_99f25ef02d0f -->|calls| aedb31dd_2729_9802_8cc8_22b3c31651b5 style 7819558a_2ee5_2bed_63fd_99f25ef02d0f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/@tailwindcss-webpack/src/index.ts lines 57–282
export default async function tailwindLoader(
this: LoaderContext<LoaderOptions>,
source: string,
): Promise<void> {
let callback = this.async()
let options = this.getOptions() ?? {}
let inputFile = this.resourcePath
let base = options.base ?? process.cwd()
let shouldOptimize = options.optimize ?? process.env.NODE_ENV === 'production'
let isCSSModuleFile = inputFile.endsWith('.module.css')
using I = new Instrumentation()
DEBUG && I.start(`[@tailwindcss/webpack] ${path.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 = !/@(import|reference|theme|variant|config|plugin|apply|tailwind)\b/.test(source)
if (canBail) {
DEBUG && I.end('Quick bail check')
DEBUG && I.end(`[@tailwindcss/webpack] ${path.relative(base, inputFile)}`)
callback(null, source)
return
}
DEBUG && I.end('Quick bail check')
}
try {
let context = getContextFromCache(inputFile, options)
let inputBasePath = path.dirname(path.resolve(inputFile))
// Whether this is the first build or not
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('Create compiler')
let compiler = await compile(source, {
from: inputFile,
base: inputBasePath,
shouldRewriteUrls: true,
onDependency: (depPath) => context.fullRebuildPaths.push(depPath),
// 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
}
// Setup the compiler if it doesn't exist yet
context.compiler ??= await createCompiler()
// Early exit if no Tailwind features are used
if (context.compiler.features === Features.None) {
DEBUG && I.end(`[@tailwindcss/webpack] ${path.relative(base, inputFile)}`)
callback(null, source)
return
}
let rebuildStrategy: 'full' | 'incremental' = 'incremental'
// Track file modification times to CSS files
DEBUG && I.start('Register full rebuild paths')
{
// Report dependencies for config files, plugins, etc.
for (let file of context.fullRebuildPaths) {
this.addDependency(path.resolve(file))
}
let files = [...context.fullRebuildPaths, inputFile]
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does tailwindLoader() do?
tailwindLoader() is a function in the tailwindcss codebase, defined in packages/@tailwindcss-webpack/src/index.ts.
Where is tailwindLoader() defined?
tailwindLoader() is defined in packages/@tailwindcss-webpack/src/index.ts at line 57.
What does tailwindLoader() call?
tailwindLoader() calls 1 function(s): getContextFromCache.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free