Skip to content
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

Faster webpack compile time #39

Closed

Conversation

codingluke
Copy link

@codingluke codingluke commented Feb 7, 2021

Hi there,

when adding custom CSS into a separate file, webpack should not have to compile the whole tailwindcss again, but only the changes in application.scss.

Moreover, I personally like it to have the custom CSS in a separate file and not in between the tailwind includes.

See: tailwindlabs/tailwindcss#443 (comment)

Before
grafik

After
grafik

I hope this will help others too. 😄

@codingluke codingluke force-pushed the feature/faster-compile-time branch from 6518ec0 to da7b43e Compare February 7, 2021 16:53
@dixpac
Copy link
Contributor

dixpac commented Feb 8, 2021

This is awesome @codingluke! Indeed on our app this speeds up recompilation time ~3x.

Maybe we could organize the files a bit differently such as:

stylesheets/
  components/
  base.scss
  components.scss
  tailwind.config.js
  utilities.css
// base.scss

// This injects Tailwind's base styles, which is a combination of Normalize.css and additional base styles.
@import 'tailwindcss/base';

// Add custom base styles, applied after the tailwind-base classes
// components.scss
`@import 'tailwindcss/components';`
  
 // Custom components....
// utilities.scss

// This injects all of Tailwind's utility classes, generated based on your config file.
@import 'tailwindcss/utilities';

// Include vendor css.
// application.js

// These are imported separately for faster Webpack recompilation
import "stylesheets/base.scss"
import "stylesheets/components.scss"
import "stylesheets/utilities.scss"

@codingluke
Copy link
Author

codingluke commented Feb 8, 2021

Hi @dixpac, Thanks for your input :)

I see your point! However, isn't application.scss kind of a convention name in Rails? Also I am not sure if the custom CSS can go directly after the `@import "tailwindcss/base". I have to check the benchmarks first.
Anyways, before I spend too much time, I would like to have @dhh feedback for the naming as naming is hard ;)

@codingluke
Copy link
Author

@dixpac, I just checked the benchmarks, it is totally fine with your structure too 👍 So when everybody can confirm on this I will adapt it.

@codingluke codingluke force-pushed the feature/faster-compile-time branch from da7b43e to a4315c1 Compare February 9, 2021 17:53
@import "tailwindcss/components";

// Import components added to `./components/` here
// https://tailwindcss.com/docs/extracting-components
Copy link
Author

Choose a reason for hiding this comment

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

@dixpac why do we need the special components folder? There is also no folder to structure the base styles (and I would do this too).

I see two ways here:

  1. Everybody should add the own structure
  2. We give them a structure (CoC). Just to do that, I am not too much experienced with tailwind ;)

@codingluke codingluke force-pushed the feature/faster-compile-time branch from a4315c1 to 4a699c5 Compare February 9, 2021 18:13
@dhh dhh closed this Aug 18, 2021
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.

3 participants