Skip to content

feat: update the tailwind plugin to suuport tailwindv4 #2819#2903

Merged
marvinhagemeister merged 33 commits intodenoland:mainfrom
SisyphusZheng:main
May 21, 2025
Merged

feat: update the tailwind plugin to suuport tailwindv4 #2819#2903
marvinhagemeister merged 33 commits intodenoland:mainfrom
SisyphusZheng:main

Conversation

@SisyphusZheng
Copy link
Contributor

@SisyphusZheng SisyphusZheng commented May 9, 2025

Inspired by #2819, #2829, and https://github.com/pakornv/fresh-plugin-tailwindcss, I made minimal modifications to the plugin-tailwind, I originally intended to update based on #2829, but I was informed by the system that I couldn't push.

Due to the breaking changes in Tailwind v4, some PostCSS plugins are no longer required. Additionally, I updated the syntax in the /www directory. The /www directory now uses the updated plugin supported by Tailwind v4.I think this has made initial progress.

What This PR Solves

The Tailwind plugin has been updated to support Tailwind v4, and it is currently functioning well both in the repository's www directory and in the initialized project which for test.

--patch-1

1. Dependency Optimization

  • Removed cssnano dependency, using Tailwind v4's built-in optimization(Based on @csvn 's suggestion)
  • Removed autoprefixer dependency
  • Updated tailwind-plugin version number

2. Build Configuration Adjustments

  • Added --node-modules-dir parameter to /www task for Tailwind v4 support (Based on @marvinhagemeister 's suggestion)
  • Added --allow-scripts parameter to enable @tailwindcss/oxide execution

3. Code Adaptation

  • Modified Tailwind-related code in /www to support Tailwind v4
  • Updated dependency configuration in deno.json

4. Feature Restoration

  • Added imagescript and astral dependencies to restore screenshot functionality lost in previous PR updates
  • Fixed the issue where the tailwind-plugin dependency was incorrectly pointing to the JSR package instead of the local repository source code in previous PR.

--patch-2

  • Upgraded Tailwind CSS to the latest version.
  • Removed unnecessary dependencies.
  • Enabled CSS minification by default when Fresh is in production mode.
  • Updated docs/canary/examples/migration-guide.md to support the new Tailwind plugin format.
  • Updated init/src/init.ts to support the new Tailwind version and plugin version, use new @import "tailwindcss", and generate the new plugin format.
  • Updated init/src/init_test.ts: tests now expect css to match /tailwindcss/ instead of /@tailwind/.
  • Removed plugin-tailwindcss/src/types.ts as it is no longer needed, and updated plugin-tailwindcss/src/mod.ts and www/dev.ts to support the new format.

Co-authored-by: Asher Gomez ashersaupingomez@gmail.com

--patch-3

Addressing @marvinhagemeister feedback, this patch reverts the unintended loss of PR #2960's changes caused by merge conflicts.

--patch-4

I initialized a project according to the migration documentation and used @fresh/update to test whether the plugin works properly with v2-alpha-34. The results show that it works fine.

--patch-5

As plugin, work fine with fresh v2 proj, can check: fresh-tailwindv4-template

How Testing Was Conducted

Local Environment Testing

  1. Environment Cleanup
rm -rf ./.cache/deno deno.lock node_modules
  1. Test Execution
deno task www
  1. Result Verification
  • Checked functionality in local /www environment
  • Confirmed all features working properly

Codespace Environment Testing

As plugin for New Fresh v2 proj Environment Testing

@SisyphusZheng
Copy link
Contributor Author

Most of the modifications were made to address deployment issues caused by unintended bot pushes. The website, now supported by new plugin (Tailwind v4), is functioning properly in the local environment.
screenshot-1746821392290

@SisyphusZheng SisyphusZheng marked this pull request as draft May 10, 2025 06:30
@SisyphusZheng
Copy link
Contributor Author

hello there, I attempted to make the plugin-tailwind support tailwind version 4 based on #2819, #2829, and https://github.com/pakornv/fresh-plugin-tailwind. It worked properly under the condition of "nodeModulesDir": "auto", and the "/www" functioned normally after the modification. However, when I tried to remove the support for node_modules, I encountered a situation where @tailwindcss/oxide (the new engine of Tailwind v4, written in Rust) didn't provide support. Due to the breaking changes in version 4, the new @tailwindcss/postcss will attempt to call @tailwindcss/oxide, and it currently seems that this issue cannot be easily resolved (it appears so).

marvinhagemeister pushed a commit that referenced this pull request May 19, 2025
Updates relating to Tailwind CSS v4 can be handled in #2903 or #2829.
@marvinhagemeister
Copy link
Collaborator

Personally, I'm good with requiring nodeModules: "auto". We need that anyway to support the vscode tailwindcss plugin

@marvinhagemeister
Copy link
Collaborator

No need to close the PR. Would've loved to get this in

@SisyphusZheng
Copy link
Contributor Author

No need to close the PR. Would've loved to get this in

I'm encountering too many file conflicts in this old branch and dealing with this issue for the time being. Thank you for your support.

@SisyphusZheng SisyphusZheng reopened this May 19, 2025
@SisyphusZheng
Copy link
Contributor Author

SisyphusZheng commented May 19, 2025

What This PR Solves

Major Updates

1. Dependency Optimization

  • Removed cssnano dependency, using Tailwind v4's built-in optimization(Based on @csvn 's suggestion)
  • Removed autoprefixer dependency
  • Updated tailwind-plugin version number

2. Build Configuration Adjustments

  • Added --node-modules-dir parameter to /www task for Tailwind v4 support (Based on @marvinhagemeister 's suggestion)
  • Added --allow-scripts parameter to enable @tailwindcss/oxide execution

3. Code Adaptation

  • Modified Tailwind-related code in /www to support Tailwind v4
  • Updated dependency configuration in deno.json

4. Feature Restoration

  • Added imagescript and astral dependencies to restore screenshot functionality lost in previous PR updates
  • Fixed the issue where the tailwind-plugin dependency was incorrectly pointing to the JSR package instead of the local repository source code in previous PR.

How Testing Was Conducted

Local Environment Testing

  1. Environment Cleanup
rm -rf ./.cache/deno deno.lock node_modules
  1. Test Execution
deno task www
  1. Result Verification
  • Checked functionality in local /www environment
  • Confirmed all features working properly

Code Inspection

  • Passed deno task ok check

Current Issues

Pending Issues

  1. Plugin Stability
    • Currently only tested in local environment
    • Needs JSR deployment for comprehensive testing

@SisyphusZheng
Copy link
Contributor Author

--patch-3
Addressing @marvinhagemeister feedback, this patch reverts the unintended loss of PR #2960's changes caused by merge conflicts.

@SisyphusZheng
Copy link
Contributor Author

SisyphusZheng commented May 20, 2025

--patch-4
I initialized a project according to the migration documentation and used @fresh/update to test whether the plugin works properly with v2-alpha-34. The results show that it works fine.

Meanwhile, I encountered the same problem as issue #2973 during the project upgrade to V2. The buttons don't seem to work, and currently, I'm not sure what's causing this problem.

--patch 5
As plugin, work fine with fresh v2 proj, can check: fresh-tailwindv4-template

Copy link
Collaborator

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for doing this, this is great!

@marvinhagemeister marvinhagemeister merged commit 40e7747 into denoland:main May 21, 2025
7 checks passed
marvinhagemeister added a commit that referenced this pull request May 21, 2025
…2903)" (#2988)

Reverts tailwind v4 update. Something is wrong with the CSS files on
fresh.deno.dev 😢
@marvinhagemeister
Copy link
Collaborator

Had to revert in #2988 because the styles on fresh.deno.dev were somehow missing. Not sure yet why.

@SisyphusZheng
Copy link
Contributor Author

Had to revert in #2988 because the styles on fresh.deno.dev were somehow missing. Not sure yet why.

Sorry this happened😟. I checked plugins, local environment and codespace—styles are fine. Tried deploying fork to Deno Deploy, but it’s slow and affects PR. Not sure if there are other issues. I’ll track progress and hope to be kept informed. Thanks for your help.

@marvinhagemeister
Copy link
Collaborator

Na no worries, it isn't your fault. My suspicion is that something with nodeModulesDir + the esbuild deno loader is broken. I couldn't repro the error locally either. This could've happened to anyone, myself included. So don't worry 👍

@Yakumo-Yukari
Copy link

error: Uncaught (in promise) Error: It looks like you're trying to use `tailwindcss` directly as a PostCSS plugin. The PostCSS plugin has moved to a separate package, so to continue using Tailwind CSS with PostCSS you'll need to install `@tailwindcss/postcss` and update your PostCSS configuration.
    at mn (fresh-project/node_modules/.deno/tailwindcss@4.1.8/node_modules/tailwindcss/dist/chunk-FEUCFEMW.mjs:35:2121)
    at Module.initTailwind (https://deno.land/x/fresh@1.7.3/plugins/tailwind/compiler.ts:68:5)
    at async initTailwind (https://deno.land/x/fresh@1.7.3/plugins/tailwind.ts:11:10)
    at async Object.configResolved (https://deno.land/x/fresh@1.7.3/plugins/tailwind.ts:91:21)
    at async Promise.all (index 0)
    at async getServerContext (https://deno.land/x/fresh@1.7.3/src/server/context.ts:79:5)
    at async dev (https://deno.land/x/fresh@1.7.3/src/dev/dev_command.ts:57:17)
    at async fresh-project/dev.ts:8:1
Watcher Process failed. Restarting on file change...

When can I get it? I am currently encountering an error using Tailwind CSS 4

@SisyphusZheng
Copy link
Contributor Author


error: Uncaught (in promise) Error: It looks like you're trying to use `tailwindcss` directly as a PostCSS plugin. The PostCSS plugin has moved to a separate package, so to continue using Tailwind CSS with PostCSS you'll need to install `@tailwindcss/postcss` and update your PostCSS configuration.

    at mn (fresh-project/node_modules/.deno/tailwindcss@4.1.8/node_modules/tailwindcss/dist/chunk-FEUCFEMW.mjs:35:2121)

    at Module.initTailwind (https://deno.land/x/fresh@1.7.3/plugins/tailwind/compiler.ts:68:5)

    at async initTailwind (https://deno.land/x/fresh@1.7.3/plugins/tailwind.ts:11:10)

    at async Object.configResolved (https://deno.land/x/fresh@1.7.3/plugins/tailwind.ts:91:21)

    at async Promise.all (index 0)

    at async getServerContext (https://deno.land/x/fresh@1.7.3/src/server/context.ts:79:5)

    at async dev (https://deno.land/x/fresh@1.7.3/src/dev/dev_command.ts:57:17)

    at async fresh-project/dev.ts:8:1

Watcher Process failed. Restarting on file change...

When can I get it? I am currently encountering an error using Tailwind CSS 4

You encountered this information when using Tailwind v4 because the change brought by this Feat was reverted. Currently, it seems there are issues with the Esbuild Loader and NodeModules, and further fixes and attempts are still needed.

However, for now, you can try the plugin by @pakornv: https://github.com/pakornv/fresh-plugin-tailwindcss. Based on this, I also provide a template initialization project for Fresh V2 with Tailwind v4 that is closer to this PR and the corresponding modifications plugin: https://github.com/SisyphusZheng/fresh-project-test/tree/main/fresh-tailwindv4-template.

@SisyphusZheng SisyphusZheng mentioned this pull request Jul 18, 2025
marvinhagemeister added a commit that referenced this pull request Jul 21, 2025
update /www and tailwind-plugin to support tailwind v4.

Thanks to the merge of #3034, the work of integrating and advancing
#2903 is promoted.

related #3034 
related #2903 

close #3056
close #2819

--patch-1 
based on review,

1. del compiler and make it more clean and simple,
2.  fix init tailwind part,
3. fix test tailwind part

--patch-2

1. fix the docs 
2. fix the docs of plugin and version

--patch-3
1. Addressed various maintenance tasks (chores)
2. Updated the Tailwind CSS plugin to align with this release. Generated
a fresh project using the updated init configuration and
3. deployed it via Deno Deploy EA. Deployment is functioning correctly.

--patch-4
Move postcss imports to Tailwind section in init script

--patch-5
Refactored Tailwind plugin type definitions by copying PluginOptions
properties from @tailwindcss/postcss and adding Fresh-specific exclude
option, while exporting types from package entrypoint for better
accessibility.

Test Project: https://fresh.fresh-press.deno.net/
Test Project Repository:
https://github.com/SisyphusZheng/fresh-tailwindv4
Test Plugin: https://jsr.io/@freshpress/fresh-plugin-tailwind@1.0.0

---------

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
Co-authored-by: Marvin Hagemeister <marvin@deno.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants