Skip to content

How to import relative css files? #39

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

Closed
thomasvanholder opened this issue Oct 16, 2021 · 8 comments
Closed

How to import relative css files? #39

thomasvanholder opened this issue Oct 16, 2021 · 8 comments

Comments

@thomasvanholder
Copy link
Contributor

thomasvanholder commented Oct 16, 2021

The bundle:css command bundles the app/assets/stylesheets/application.tailwind.css file. How to include relative css files to be bundled too?

File structure

|-- stylesheets
  |-- application.tailwind.css  
  |-- custom.css   
@tailwind base;
@tailwind components;
@tailwind utilities;

@import "custom";  /* does not include the relative file.*/
@scotteknight
Copy link

scotteknight commented Oct 20, 2021

I just had to figure this out too. In order to import any custom css files you have to use the postcss-import plugin with a postcss.config.js file as described here: https://tailwindcss.com/docs/using-with-preprocessors#build-time-imports

Once you set that up then your application.tailwind.css file can look like:

@import "tailwindcss/base";

@import "tailwindcss/components";

@import "./custom.css";

@import "tailwindcss/utilities";

where your custom.css file is included.

Then add the--postcss flag in your build:css script
Here is a blog post I also used for reference: https://dev.to/phawk/the-best-way-to-run-tailwind-css-on-rails-302c

I'm still not sure whether the other postcss plugins are required like I had when using in webpacker, e.g. flexbugs-fixes, preset-env etc. I basically kept my postcss.config.js file that same as before with webpacker but had to yarn add the required missing plugins to my package.json.

@scotteknight
Copy link

Just noticed this was referenced in issue #24 as well.

@dhh
Copy link
Member

dhh commented Nov 5, 2021

Documented the this question as part of the FAQ: 2a17da2.

@dhh dhh closed this as completed Nov 5, 2021
@RomanKrasavtsev
Copy link

It should also be mentioned here that in order to use <%= stylesheet_link_tag "application", "custom" %> we have to specify //= link_tree ../stylesheets in app/assets/config/manifest.js. Correct me if I am wrong.

@dhh
Copy link
Member

dhh commented Nov 8, 2021

That's right. But also the default setup. So you'd have to have actively removed it not to see that. Or have you found another way it's missing?

@simon-bigsofa
Copy link

simon-bigsofa commented Nov 9, 2021

Had to add //= link_tree ../stylesheets to app/assets/config/manifest.js manually after a fresh install.

Looks like it's being removed from the default setup here during install:

gsub_file "app/assets/config/manifest.js", "//= link_directory ../stylesheets .css\n", ""

@dhh
Copy link
Member

dhh commented Nov 9, 2021

Hmm, yeah, there's that conflict again where we're using the same directory for both styles that need compiling and those that do not. Need to figure a better solution for this.

@jmarsh24
Copy link

This is still an issue on new builds

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

No branches or pull requests

6 participants