Node.js-specific utilities and runtime functionality for Tailwind CSS v4, providing compilation tools, module dependency analysis, source map handling, path normalization, and optimization utilities.
npx @tessl/cli install tessl/npm-tailwindcss--node@4.1.0@tailwindcss/node provides Node.js-specific utilities and runtime functionality for Tailwind CSS v4, including compilation tools, module dependency analysis, source map handling, path normalization, and optimization utilities. It serves as the core Node.js integration layer for Tailwind CSS, enabling server-side processing of styles, hot module reloading support, and seamless integration with Node.js build tools and development workflows.
npm install @tailwindcss/nodeimport {
compile,
compileAst,
Instrumentation,
optimize,
normalizePath,
toSourceMap,
env
} from "@tailwindcss/node";For CommonJS:
const {
compile,
compileAst,
Instrumentation,
optimize,
normalizePath,
toSourceMap,
env
} = require("@tailwindcss/node");Specialized imports:
// Require cache management
import { clearRequireCache } from "@tailwindcss/node/require-cache";
// ESM cache loader (used internally by Node.js module system)
// Note: This is registered automatically when importing the main moduleimport { compile, CompileOptions, optimize } from "@tailwindcss/node";
// Compile Tailwind CSS with Node.js-specific features
const options: CompileOptions = {
base: "/path/to/project",
onDependency: (path: string) => {
console.log("Dependency:", path);
},
shouldRewriteUrls: true,
};
const compiler = await compile(`
@tailwind base;
@tailwind components;
@tailwind utilities;
`, options);
// Get the compiled CSS
const css = compiler.build();
// Optimize the CSS for production
const optimized = optimize(css, {
minify: true,
file: "styles.css"
});
console.log(optimized.code);@tailwindcss/node is built around several key components:
Core Tailwind CSS compilation functionality with Node.js-specific module loading, dependency tracking, and file system integration.
function compile(css: string, options: CompileOptions): Promise<Compiler>;
function compileAst(ast: AstNode[], options: CompileOptions): Promise<Compiler>;
interface CompileOptions {
base: string;
from?: string;
onDependency: (path: string) => void;
shouldRewriteUrls?: boolean;
polyfills?: Polyfills;
customCssResolver?: Resolver;
customJsResolver?: Resolver;
}
type Resolver = (id: string, base: string) => Promise<string | false | undefined>;Built-in performance monitoring and profiling tools with timer support and automatic reporting for development workflows.
class Instrumentation implements Disposable {
constructor(defaultFlush?: (message: string) => void);
hit(label: string): void;
start(label: string): void;
end(label: string): void;
reset(): void;
report(flush?: (message: string) => void): void;
[Symbol.dispose](): void;
}Lightning CSS-based optimization with minification, nesting, media query processing, and browser compatibility transformations.
function optimize(input: string, options?: OptimizeOptions): TransformResult;
interface OptimizeOptions {
file?: string;
minify?: boolean;
map?: string;
}
interface TransformResult {
code: string;
map: string | undefined;
}Comprehensive source map generation, manipulation, and serialization with inline embedding support for debugging workflows.
function toSourceMap(map: DecodedSourceMap | string): SourceMap;
interface SourceMap {
readonly raw: string;
readonly inline: string;
}
type DecodedSource = {
url: string;
content: string;
};
type DecodedSourceMap = {
mappings: Array<{
generatedPosition: { line: number; column: number };
originalPosition?: { line: number; column: number; source: DecodedSource };
name?: string;
}>;
};Cross-platform path normalization utilities for consistent file path handling across Windows and Unix systems.
function normalizePath(originalPath: string): string;Recursive module dependency analysis with support for TypeScript, ESM, and CommonJS import patterns.
function getModuleDependencies(absoluteFilePath: string): Promise<string[]>;CSS URL rewriting functionality for asset path management and relative URL transformation in build processes.
function rewriteUrls(options: {
css: string;
base: string;
root: string;
}): Promise<string>;Node.js module cache management for hot module reloading and development workflows.
function clearRequireCache(files: string[]): void;The package supports several environment configurations:
const env: {
readonly DEBUG: boolean;
};The DEBUG environment variable supports various patterns:
DEBUG=true or DEBUG=1 - Enable debuggingDEBUG=false or DEBUG=0 - Disable debuggingDEBUG=* - Enable all debug modesDEBUG=tailwindcss - Enable Tailwind CSS debuggingDEBUG=-tailwindcss - Explicitly disable Tailwind CSS debuggingCore types used throughout the package:
// Re-exported from tailwindcss
enum Features {
// CSS feature flags for compilation
}
interface Polyfills {
// CSS polyfill configuration
}
// Internal types
interface AstNode {
// AST node structure (from tailwindcss)
}
interface Compiler {
// Compilation result with build methods
build(): string;
root?: { pattern: string } | 'none';
}