-
Notifications
You must be signed in to change notification settings - Fork 12k
Tailwind support #20015
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
Comments
Thanks for bringing up these points! Glad we can draw from the experience of other tools to help craft an improved developer experience. We talked briefly about this in our tooling issue triage. Regarding point 1: we're looking into an Angular-specific solution to be more comprehensive. Enabling PurgeCSS directly in Tailwind would likely not work well with Angular templates out of the box. We're hoping we can optimize this a little better with direct support in Angular. Regarding point 2: |
Just curious why not just to set Looks like once it was added #2110 |
While a newly generated project does have a However, if Tailwind had a programmatic option (plugin constructor?) for setting its production mode (with a default to use the environment variable), the Angular CLI could potentially link that setting to the build system's style optimization settings. |
Thanks for the clarification. Make sense. Tailwind has |
This is actually a very good point. With all this in mind, it would be helpful to also provide an option to opt-out of Tailwind support if the developers deem other tools (like |
Please provide an opt-out in a patch release, this feature is breaking existing apps/installations and it's pretty interrupting. I think this does not belong in a |
This is config I use: module.exports = {
purge: {
enabled: process?.argv?.indexOf("build") !== -1,
content: [
"./src/**/*.html",
"./src/**/*.ts",
"./projects/**/*.html",
"./projects/**/*.ts"
]
},
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {},
plugins: [],
} With this, when you run |
Looks like for now, the best way to opt-out from Angulars built-in Tailwind support and keep Taiwlind IntelliSense work in the same time is to rename
|
Hi! Thanks for sharing this. For your solution, I had to rename tailwind.config.js to tailwind.js for it to work. Otherwise, I was getting the following error: Error: ./src/app/app.component.scss Then when I ran Running Angular 11.2.0 module.exports = {
prefix: '',
purge: {
enabled: true,
content: [
'./src/**/*.{html,ts}',
]
},
darkMode: 'class', // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [require('@tailwindcss/forms'),require('@tailwindcss/typography')],
}; I think the reason is based on @vltansky is because I'm ruinning node 12.13 :P |
For those interested, this is what I end up with, to support purge: {
// Workaround to run purge only during build task (see: https://github.com/angular/angular-cli/issues/20015)
// This should match the nx build task name of any project:
// ex: "app1:build:production" or "app2:build:staging"
enabled: process?.argv?.some(arg => arg.includes(':build')),
content: ['./apps/**/*.{html,ts}', './libs/**/*.{html,ts}'],
}, |
Great that this is being worked on but really confused me how my custom webpack config was being ignored and tailwind was somehow mysteriously being invoked. Since I'm new to Angular it took me hours to get to the bottom of it. |
One of the primary motivations for providing support of Tailwind within the Angular CLI was to mitigate these type of confusing situations and similar problems for users moving forward, especially when updating their projects. While we do understand the confusion this may have caused for existing users of customized Webpack configurations, modification of the internal Webpack configuration via a custom builder is considered an experimental option. This means that no SemVer guarantees are provided regarding the content and structure of the internal Webpack configuration; and breaking changes regarding the Webpack configuration may occur in any version. Additionally, during the Angular update process, migrations may also be skipped or reduced in scope when unknown builders (with potentially unknown options and/or behavior) are present in the Angular configuration. These migration reductions may not be a problem in and of themselves as the migration may not apply to the unknown builder or the builder may provide its own migrations. However, it is something that may need to be evaluated during the update process. By officially supporting Tailwind, we hope to maximize the ability for users to continue using the official Angular builders while also allowing users to leverage their preferred tools such as Tailwind. |
@clydin that makes total sense. Then should I take that as a no for AngularCLI providing an opt-out of Tailwind support? Just want to make sure so that we ( Also on Tailwind official support, this is a great initiative from the Angular CLI team. However, supporting Tailwind but not supporting Purging is half-baked. TailwindCSS looks for either one of these two things to execute PurgeCSS:
AngularCLI doesn't set |
@nartc do you plan to continue maintaining the integration via a custom Webpack config ? |
Yes. I've been on parental leave so haven't been updating the ngneat/tailwind package but after I'm back, we'll come up with a roadmap as to what ngneat/tailwind will provide moving forwards. That is also depends on AngularCLI team responses in this thread. |
A workaround for the purge issue is:
One thing worth noting is that the paths in
Trying to glob everything like this:
results in a much longer build time, presumably as a result of searching |
The For the purge setting, it would be preferred if Tailwind itself provided a more fine-grained method to specify its production mode. Two potential options for this are a programmatic option when initializing the plugin or a targeted environment variable (e.g., For the |
Looks like tailwind working on JIT compilation, that wouldn't need purge functionality / prod flags. Long term this can be the best solution. Although right now it's still experimental.
Regarding |
Regarding the
This could instead be transformed as the following:
Some additional background: https://developer.mozilla.org/en-US/docs/Web/CSS/Selector_list#selector_list_invalidation |
We talked a bit about the PurgeCSS issue in the CLI triage meeting today but haven't made a decision yet. I made a separate issue to look into the best way to provide build context to external tool config files: #20253. This problem applies to all possible external tools (though I think Tailwind is the first), so we want to be careful about how we approach the issue and make sure the approach is scalable and decoupled from the specific tools in the best possible way. As others have mentioned, the simplest workaround for the PurgeCSS problem at the moment is to just set NODE_ENV=production ng build --configuration production We'll discuss this more soon and try to come up with a complete solution/recommendation. |
You probably already know, but this might be highly relevant, while getting rid of purge - tailwind JIT compiler. |
Had some more discussion about the PurgeCSS issue today, and our current plan is to hold out to see if Tailwind JIT is able to handle this problem on its own, without any direct Angular integration. We'll test out JIT and keep an eye on it for the time being rather than implementing a unique build context solution just for Tailwind. |
So it looks like JIT is now part of tailwind and will ship with version 2.1 https://twitter.com/adamwathan/status/1378054054107041792 |
FYI: This article nicely explains problems the CLI has currently around JIT mode. https://apvarun.com/blog/tailwindcss-jit-in-angular |
Hello @lacolaco, this is what I use for the JIT mode and it works well for me: process.env.TAILWIND_MODE =
process.env.WEBPACK_DEV_SERVER === 'true' && process.argv.join(' ').indexOf('build') !== -1
? 'build'
: 'watch';
module.exports = {
mode: 'jit',
purge: ['./src/**/*.{html,ts}', './projects/**/*.{html,ts}'],
theme: {
extend: {},
},
variants: {},
plugins: [],
}; |
@ahasall,
@lacolaco, I also tried to add a postinstall script you mentioned from the blog post, but it seems it's incompatible with the newest v2.1 as they merged JIT plugin directly into Tailwind. |
hi @ahasall , I'm not able to get <button class="px-4 py-2 rounded bg-blue-400 text-white">Button</button> This does not work but the following works. Any suggestions? .btn {
@apply px-4 py-2 rounded bg-blue-400 text-white;
} <button class="btn">Button</button> |
@nartc add @import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities'; to example repo: https://github.com/vltansky/tailwind-jit-test |
ngneat/tailwind released v7 that leverage Angular CLI built-in support for, opt-in JIT and workaround for enabling purge |
I figured out what is the issue, but didn't figure out the cause.
With this setup, I get this nasty error. If I just remove this import or move it to the main SCSS file ( Now, I'm not sure where to file the issue. Can anyone suggest what is the origin of this error; tailwindcss JIT (it only happens while running in this mode)? postcss-loader? postcss? mini-css-extract-plugin? Google font import itself? |
Tailwind now has function guessProductionMode() {
const argv = process.argv.join(' ').toLowerCase();
const isProdEnv = process.env.NODE_ENV === 'production';
return isProdEnv || [' build', ':build', 'ng b', '--prod'].some(command => argv.includes(command));
}
process.env.TAILWIND_MODE = guessProductionMode() ? 'build' : 'watch'; Would be really useful if Angular CLI would set this variable instead. |
Looks good to me |
@clydin thanks for adding that. To help clarify for others, as of Angular 11.2.12 or
|
Closing since the above has been addressed. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
@clydin few things that maybe will help you ensure full TailwindCSS support, based on issues we had in
ngneat/tailwind
:process.env.NODE_ENV
isproduction
, which Angular not setting by default.https://tailwindcss.com/docs/optimizing-for-production#removing-unused-css
https://twitter.com/Nartc1410/status/1357504574479810568
none
, as tailwind will just try to prepend class with.dark
, so the result code will be something like.dark[_ng-content-**] .value[_ng-content-**]
. Also not sure what will happen withShadowDom
, tested only withemulated
. Inngneat/tailwind
we made PostCSS plugin for it: https://github.com/vltansky/postcss-ng-tailwind-in-components. Probably there are alternative solutions.https://github.com/ngneat/tailwind/issues/54
relevant to: 73b4098
The text was updated successfully, but these errors were encountered: