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
Support tailwind css #1943
Comments
We have a custom component module built using tailwindcss and PostCSS as a dependency in an Angular app. We are now planning to make a library for that custom component module so that we can use in other apps. But I have realized that using customWebpacks is not allowed in Angular libraries. But building the components again right from scratch without using tailwind seems to be really tedious. Is there a workaround ?Could someone point me in right direction as how to proceed further? |
Support for tailwincss has been included in Angular CLI 11.2, and add this support directly in ng-packagr is also being considered. That being said so far we didn't receive any compelling use-case for this. Can you please elaborate which tailwinds features would you intend to leverage when building a library? |
Thanks for your reply @alan-agius4 .
But however we can't use custom-webpack:dev-server in an Angular library because it uses As i mentioned earlier, we have a custom component module which was developed in an Angular Application and it uses tailwindCss and PostCss with a customWebpackConfig. But now, we need this component module in other applications also. The best way would be to create a private library so that other developers can just install and use it as and when required. But however I am not getting a way where I can proceed further because I can't use a customWebpackConfig for TailwindCss compilation? |
JFYI, I am more interested to know, which features of tailwind you are going to use in the component library. I am asking because in many cases you'd want to limit the usage of tailwind in a component, in order to avoid generating duplicate CSS across components. But I think allowing Tailwinds functions and directives, example |
Hi @alan-agius4 , |
Hi @dattatreyapatil0, at the moment the only workaround would be to patch the ng-packagr locally. |
Hi @alan-agius4 , |
@dattatreyapatil0, you can change this file https://github.com/ng-packagr/ng-packagr/blob/master/src/lib/styles/stylesheet-processor-worker.ts#L95 in your node_modules and than apply the patch using https://www.npmjs.com/package/patch-package NB: by doing the above you are opting to be on the unsupported path. |
Hi @alan-agius4 , I will try the way you suggested in coming days. |
Based on @alan-agius4 I think I've got it working! Although I would love to see this feature added. More and more companies are building component libraries and now that Angular is providing first class support for Tailwind in Angular applications I could see the demand for tailwind skyrocketing. Here is what I did: Add the classic tailwind dependencies: next get your tailwind config file created then add patch-package: Next either update patch:
Next add Finally you need to add your tailwind imports. To test things out I would suggest adding them to one of your component scss files and seeing if it works.
I'm not sure what the best strategy for having a common styles spreadsheet between components is. Right now I just have a styles.scss in my lib directory that import the tailwindcss that all of my other components add via the styleUrls. Hope this helps! |
hey guys, are there any updates on that? It would be super helpful, if this would be supported. |
Support for tailwind functions like |
I would also love this feature. Could u guys point me to some guidelines about making a PR for it? I'm down to help with anything possible. |
At the moment, the best workaround I have found is that the consuming project (example: website) adds the output/source folder of the library in the (The disadvantages/shortcomings for this method is mentioned at the bottom) Example A: Using the Library source directlyFolder structure
To use the library with tailwind, update module.exports = {
content: [
// how you resolve the folder is up to you. I always run build from the workspace root, hence path.join and process.cwd() is used
// the regex is essentially telling tailwind process the given file extensions, but ignore tests and storybook files
// the following will process the website's files. I use scss for stylesheets. If you use vanilla css/sass,
// include the respective extension in the regex
join(process.cwd(), 'projects/website/src', '**/!(*.stories|*.spec).{ts,html,scss}')
// the following will process the library's files.
join(process.cwd(), 'projects/libary/src', '**/!(*.stories|*.spec).{ts,html,scss}')
],
} Example B: Library in node_modules or in distFolder structure
To use the libraries with tailwind, update module.exports = {
content: [
// this the website's source files
join(process.cwd(), 'projects/website/src', '**/!(*.stories|*.spec).{ts,html,scss}')
// the following will process the library's files. If you look into the output/node_modules of the library you depend on
// you will see that the code exists in .mjs files (at least, in my case), so we'll only need that extension.
join(process.cwd(), 'dist/internal-library', '**/!(*.stories|*.spec).{mjs}'),
join(process.cwd(), 'node_modules/external-library', '**/!(*.stories|*.spec).{mjs}')
],
} DisadvantagesThe caveat is that this method expects similar configuration for the tailwind theme. It's not strictly necessary, but essentially, what'll happen is that the website's tailwind config is going to wipe away the tailwind config of the library (repeat: not override - completely replace), unless you import the library's tailwind config into the website's tailwind config and merge the theme objects as you need. This is easy for a local library, but if you are publishing the library, you might want to include the tailwind.config.js as an asset in the angular configuration, so that it is available to consumers. Note: I have not tested whether ViewEncapsulation has any effect on this. I use angular material, and anything apart from the default breaks that, so I stayed away from playing with that. |
patch for version
|
With the announcement of flex-layout's deprecation, would it be possible to prioritize this support? Tailwind is listed as a viable migration route for projects using flex-layout (https://blog.angular.io/modern-css-in-angular-layouts-4a259dca9127). It would be nice to be able to move to it more officially in libraries, for our layout needs. |
This feature adds detection of the `tailwindcss` package (https://tailwindcss.com) and provides a mechanism to automatically include support. To enable tailwindcss for a project, two actions must be taken: 1) Install `tailwindcss` (`npm install -D tailwindcss`/`yarn add -D tailwindcss`) 2) Create a tailwindcss configuration file (`tailwind.config.js`) in the project root. A configuration file in the project root takes precedence over one in the workspace root. Closes ng-packagr#1943
This feature adds detection of the `tailwindcss` package (https://tailwindcss.com) and provides a mechanism to automatically include support. To enable tailwindcss for a project, two actions must be taken: 1) Install `tailwindcss` (`npm install -D tailwindcss`/`yarn add -D tailwindcss`) 2) Create a tailwindcss configuration file (`tailwind.config.js`) in the project root. A configuration file in the project root takes precedence over one in the workspace root. Closes ng-packagr#1943
This feature adds detection of the `tailwindcss` package (https://tailwindcss.com) and provides a mechanism to automatically include support. To enable tailwindcss for a project, two actions must be taken: 1) Install `tailwindcss` (`npm install -D tailwindcss`/`yarn add -D tailwindcss`) 2) Create a tailwindcss configuration file (`tailwind.config.js`) in the project root. A configuration file in the project root takes precedence over one in the workspace root. Closes #1943
This issue has been automatically locked due to inactivity. |
Adding custom postcss plugins is currently not supported, We'll be looking at this in the future.
Originally posted by @alan-agius4 in #1418 (comment)
The text was updated successfully, but these errors were encountered: