-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update tailwind to version 4.0.0 #107
Conversation
Previously the README recommended running the tailwind executable from the assets directory in the `mix tailwind` task. Since tailwind 4.0.0 searches for source files in the directory it is run from, we instead recommend running the executable from the parent directory.
Also, bump old version used to test updates. It might help if GitHub does any sort of caching of release assets.
@aptinio 🙏. Is there any breaking changes that need to be documented in this repo specifically in the README? |
@snewcomer, moving to Tailwind v4's CSS configuration is a breaking change if an earlier Tailwind version is chosen by the user. Tailwind v4 does provide the We could release a 0.3 version for Tailwind v4 support. What do you think? |
I've tested this branch to work with phoenixframework/phoenix#5990 with the following changes to that PR:
|
@aptinio interesting, I didn't need to install |
{:phoenix, "~> 1.6"}, | ||
{:tailwind, "~> 0.1.8", runtime: Mix.env() == :dev} | ||
{:phoenix, "~> 1.7"}, | ||
{:tailwind, "~> 0.2.4", runtime: Mix.env() == :dev} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's ship it as 0.3.0 once we have these changes in.
Same here. Everything just works on macOS (including the Heroicons plugin; EDIT: no, the plugin doesn't work). |
@stefanchrobot Do you have a node_modules folder with tailwindcss directory inside? I tried the PR in Phoenix yesterday and I could reproduce the heroicons plugin not working out of the box. |
Sorry, I'm actually experiencing the same thing. The plugin is not working. I had |
I'm running on Linux. When I run
And before I remove the heroicons plugin and run
Running:
exits with 1 with no output. There's a missing parenthesis in the heroicons plugin in phoenixframework/phoenix#5990, but fixing it doesn't help with the exit code 1. |
I think both of these are upstream issues in the tailwind cli linux binary. I can file them later upstream. |
@aptinio there's already an upstream issue here: tailwindlabs/tailwindcss#15235, but feel free to open one for the missing watchman! |
Reported tailwindlabs/tailwindcss#15703. Apparently, watching still works even if the following is included in the output:
|
I don't have this issue on macOS, but I am also experiencing the following error related to the
Everything works fine if I remove the plugin. I noticed that the root cause of the error might be the following line of the plugin: const plugin = require('tailwindcss/plugin') Unfortunately, you don't need this because you can just export a basic function (no need to wrap it into So this seems to be a valid plugin in v4: # plugin.js
module.exports = function({ addVariant }) {
addVariant('inverted', '@media (inverted-colors: inverted)')
addVariant('hocus', ['&:focus', '&:hover'])
} Therefore, exporting a basic function in Here is the full const fs = require("fs")
const path = require("path")
module.exports = function ({ matchComponents, theme }) {
const iconsDir = path.join(__dirname, '../../deps/heroicons/optimized')
const values = {}
const icons = [
['', '/24/outline'],
['-solid', '/24/solid'],
['-mini', '/20/solid'],
['-micro', '/16/solid']
]
icons.forEach(([suffix, dir]) => {
fs.readdirSync(path.join(iconsDir, dir)).forEach(file => {
const name = path.basename(file, '.svg') + suffix
values[name] = { name, fullPath: path.join(iconsDir, dir, file) }
})
})
matchComponents({
hero: ({ name, fullPath }) => {
const content = fs.readFileSync(fullPath).toString().replace(/\r?\n|\r/g, '')
let size = theme('spacing.6')
if (name.endsWith('-mini')) {
size = theme('spacing.5')
} else if (name.endsWith('-micro')) {
size = theme('spacing.4')
}
return {
[`--hero-${name}`]: `url('data:image/svg+xml;utf8,${content}')`,
'-webkit-mask': `var(--hero-${name})`,
mask: `var(--hero-${name})`,
'mask-repeat': 'no-repeat',
'background-color': 'currentColor',
'vertical-align': 'middle',
display: 'inline-block',
width: size,
height: size
}
}
}, { values })
} |
It looks like this is a valid way to build plugins: https://github.com/tailwindlabs/tailwindcss/blob/main/packages/internal-example-plugin/index.js A plugin seems to be just this: export type PluginFn = (api: PluginAPI) => void and the function createPlugin(handler: PluginFn, config?: Partial<Config>): PluginWithConfig {
return {
handler,
config,
}
} which is just: export type PluginWithConfig = {
handler: PluginFn
config?: UserConfig
/** @internal */
reference?: boolean
} But I think this is a workaround, so it still needs fixing upstream. |
Related PR: tailwindlabs/tailwindcss#15934 |
Found another issue: the prebuilt packages have changed between v3 and v4.
This requires updating this function. I think this would definitely warrant a version bump of More importantly, though, we need to figure out a way to pick musl vs non-musl binaries. Things are currently failing for me when trying to build the app on Alpine in Docker. Not sure if there is a way to detect musl. Should we have another option in the config? Something along the lines of: config :tailwind,
version: "4.0.3",
musl: true # only applies if target is "linux"; default is false If someone was developing on non-musl and building on musl, they could probably control this with an ENV var. |
Maybe a better approach would be to provide
|
@stefanchrobot we can automatically detect musl - I opened #109 which also adds a config option to override if necessary. |
@Flo0807 @stefanchrobot I can confirm that the heroicons plugin works when we directly export the function. If this is officially supported by Tailwind, we could go forward with that change. Sadly, v4 doesn't seem to have any documentation on plugins, while v3 had https://v3.tailwindcss.com/docs/plugins, so I'm not sure :( |
This is great! I think it would be best to incorporate your PR into this one and also update the list of targets: the musl binaries are only available for v4; also v4 no longer provides targets like "linux-armv7". |
I'd vote for moving forward with the change so that this gets unblocked. We could revert to using |
I think we can merge them separately as well, and then do a new release with all changes incorporated. I'm not sure if we should remove the armv7 targets. You could use the new library version with Tailwind v3 as well. There's also the freebsd targets which aren't officially provided by Tailwind. If we do remove it, I think we should document which versions of Tailwind are expected to work with which version of the library.
The heroicon plugin doesn't block the change here in the tailwind repo. It's only an issue for Phoenix 1.8 :) |
This looks good to go my only concern is that, as soon as update the README, people will start relying on that. So we need to either postpone the README changes or hold merging this branch. |
@josevalim so you're worried people will try to follow the |
Compromise: let's add a "Updating to Tailwind v4" section to the README, explaining that main/v0.3+ is Tailwind v4 and with the steps to migrate? |
I'll merge and then send a new PR targeting main! |
Thank you everyone! 🙌🏻 |
@SteffenDE, @josevalim, for what it's worth, I think it'll be more future-proof to tell people that v0.3 only supports Tailwind v4 and link them to v0.2 docs for Tailwind < v4. I think it'll also keep the README neat and tidy. |
Thanks! Running latest |
This PR is made on top of @leifmetcalf's #103. It bumps the versions now that Tailwind CSS v4.0 is out.