MCPcopy
hub / github.com/tailwindlabs/tailwindcss / tailwindcss

Function tailwindcss

packages/@tailwindcss-postcss/src/index.ts:71–363  ·  view source on GitHub ↗
(opts: PluginOptions = {})

Source from the content-addressed store, hash-verified

69}
70
71function tailwindcss(opts: PluginOptions = {}): AcceptedPlugin {
72 let base = opts.base ?? process.cwd()
73 let optimize = opts.optimize ?? process.env.NODE_ENV === 'production'
74 let shouldRewriteUrls = opts.transformAssetUrls ?? true
75
76 return {
77 postcssPlugin: '@tailwindcss/postcss',
78 plugins: [
79 // We need to handle the case where `postcss-import` might have run before
80 // the Tailwind CSS plugin is run. In this case, we need to manually fix
81 // relative paths before processing it in core.
82 fixRelativePathsPlugin(),
83
84 {
85 postcssPlugin: 'tailwindcss',
86 async Once(root, { result, postcss }) {
87 using I = new Instrumentation()
88
89 let inputFile = result.opts.from ?? ''
90 let isCSSModuleFile = inputFile.endsWith('.module.css')
91
92 DEBUG && I.start(`[@tailwindcss/postcss] ${relative(base, inputFile)}`)
93
94 // Bail out early if this is guaranteed to be a non-Tailwind CSS file.
95 {
96 DEBUG && I.start('Quick bail check')
97 let canBail = true
98 root.walkAtRules((node) => {
99 if (
100 node.name === 'import' ||
101 node.name === 'reference' ||
102 node.name === 'theme' ||
103 node.name === 'variant' ||
104 node.name === 'config' ||
105 node.name === 'plugin' ||
106 node.name === 'apply' ||
107 node.name === 'tailwind'
108 ) {
109 canBail = false
110 return false
111 }
112 })
113 if (canBail) return
114 DEBUG && I.end('Quick bail check')
115 }
116
117 let context = getContextFromCache(postcss, inputFile, opts)
118 let inputBasePath = inputFile ? path.dirname(path.resolve(inputFile)) : base
119
120 // Whether this is the first build or not, if it is, then we can
121 // optimize the build by not creating the compiler until we need it.
122 let isInitialBuild = context.compiler === null
123
124 async function createCompiler() {
125 DEBUG && I.start('Setup compiler')
126 if (context.fullRebuildPaths.length > 0 && !isInitialBuild) {
127 clearRequireCache(context.fullRebuildPaths)
128 }

Callers 1

index.test.tsFile · 0.70

Calls 1

fixRelativePathsPluginFunction · 0.85

Tested by

no test coverage detected