Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
cc17fa75
Commit
cc17fa75
authored
Sep 04, 2025
by
Niklas Mischkulnig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Skip PostCSS if possible for Tailwind
parent
6472fb5c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
2 deletions
+60
-2
postcss.rs
turbopack/crates/turbopack-node/src/transforms/postcss.rs
+60
-2
No files found.
turbopack/crates/turbopack-node/src/transforms/postcss.rs
View file @
cc17fa75
use
anyhow
::{
Context
,
Result
,
bail
};
use
anyhow
::{
Context
,
Result
,
bail
};
use
indoc
::
formatdoc
;
use
indoc
::
formatdoc
;
use
once_cell
::
sync
::
Lazy
;
use
regex
::
Regex
;
use
serde
::{
Deserialize
,
Serialize
};
use
serde
::{
Deserialize
,
Serialize
};
use
serde_json
::
Value
;
use
turbo_rcstr
::{
RcStr
,
rcstr
};
use
turbo_rcstr
::{
RcStr
,
rcstr
};
use
turbo_tasks
::{
use
turbo_tasks
::{
Completion
,
Completions
,
NonLocalValue
,
ResolvedVc
,
TaskInput
,
TryFlatJoinIterExt
,
Vc
,
Completion
,
Completions
,
FxIndexMap
,
NonLocalValue
,
ResolvedVc
,
TaskInput
,
TryFlatJoinIterExt
,
fxindexmap
,
trace
::
TraceRawVcs
,
Vc
,
fxindexmap
,
trace
::
TraceRawVcs
,
};
};
use
turbo_tasks_bytes
::
stream
::
SingleValue
;
use
turbo_tasks_bytes
::
stream
::
SingleValue
;
use
turbo_tasks_fs
::{
use
turbo_tasks_fs
::{
...
@@ -450,6 +453,52 @@ impl GenerateSourceMap for PostCssTransformedAsset {
...
@@ -450,6 +453,52 @@ impl GenerateSourceMap for PostCssTransformedAsset {
}
}
}
}
#[turbo_tasks
::
function]
async
fn
config_contains_only_tailwind
(
config_path
:
FileSystemPath
)
->
Result
<
Vc
<
bool
>>
{
#[derive(Deserialize)]
struct
PostCssConfig
{
plugins
:
FxIndexMap
<
String
,
Value
>
,
}
if
!
matches!
(
config_path
.extension_ref
(),
Some
(
"json"
|
"postcssrc"
))
{
// We can only parse JSON statically
return
Ok
(
Vc
::
cell
(
false
));
}
let
FileContent
::
Content
(
config
)
=
&*
config_path
.read
()
.await
?
else
{
return
Ok
(
Vc
::
cell
(
false
));
};
let
Ok
(
config
):
serde_json
::
Result
<
PostCssConfig
>
=
serde_json
::
from_reader
(
config
.read
())
else
{
// Silently ignore parse errors
return
Ok
(
Vc
::
cell
(
false
));
};
// Tailwind 4: `@tailwindcss/postcss`
// Tailwind 3: `tailwindcss`
Ok
(
Vc
::
cell
(
config
.plugins
.keys
()
.all
(|
v
|
{
v
==
"@tailwindcss/postcss"
||
v
==
"tailwindcss"
})))
}
// Whether the PostCSS transform can be skipped, as none of the enabled plugins would effect the
// source in any way.
//
// In particular, if Tailwind is the only PostCSS plugin and the CSS doesn't contain any tailwind
// specific directives, then there is no need to execute the transform.
async
fn
skip_transform
(
config_path
:
FileSystemPath
,
source
:
&
str
)
->
Result
<
bool
>
{
if
!*
config_contains_only_tailwind
(
config_path
)
.await
?
{
return
Ok
(
false
);
}
// Tailwind 4: `@import "tailwindcss"`
// Tailwind 3: `@tailwind`
static
TAILWIND_REGEX
:
Lazy
<
Regex
>
=
Lazy
::
new
(||
Regex
::
new
(
r
"@tailwind|tailwindcss"
)
.unwrap
());
Ok
(
!
TAILWIND_REGEX
.is_match
(
source
))
}
#[turbo_tasks
::
value_impl]
#[turbo_tasks
::
value_impl]
impl
PostCssTransformedAsset
{
impl
PostCssTransformedAsset
{
#[turbo_tasks
::
function]
#[turbo_tasks
::
function]
...
@@ -494,6 +543,15 @@ impl PostCssTransformedAsset {
...
@@ -494,6 +543,15 @@ impl PostCssTransformedAsset {
.cell
());
.cell
());
};
};
let
content
=
content
.content
()
.to_str
()
?
;
let
content
=
content
.content
()
.to_str
()
?
;
if
skip_transform
(
config_path
.clone
(),
&
content
)
.await
?
{
return
Ok
(
ProcessPostCssResult
{
content
:
self
.source
.content
()
.to_resolved
()
.await
?
,
assets
:
Vec
::
new
(),
}
.cell
());
}
let
evaluate_context
=
self
.evaluate_context
;
let
evaluate_context
=
self
.evaluate_context
;
let
source_map
=
self
.source_map
;
let
source_map
=
self
.source_map
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment