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

Add runtime compile of tailwind css #30

Merged

Conversation

ryanwinchester
Copy link
Contributor

@ryanwinchester ryanwinchester commented Sep 24, 2022

This adds Beacon.RuntimeCSS.recompile!/1

It recompiles and minifies/purges Tailwind CSS based on layout and pages from the DB.

TODO (and to discuss):

  • Double check reading of templates/views in release (i.e. make sure the directories are correct)
  • Unit Test

NOTE: This adds the CSS to assigns in the module loader but not to any rendered pages. My main goal was getting CSS that could compile/recompile at runtime.

Also, there are also probably better ways to handle custom tailwind configs, but this is a starting point?

@ryanwinchester ryanwinchester force-pushed the feature/runtime-css-compile branch 7 times, most recently from 569ed34 to 95cbece Compare September 24, 2022 23:22
@ryanwinchester ryanwinchester marked this pull request as ready for review October 18, 2022 02:06
@bcardarella
Copy link
Contributor

@ryanwinchester we're starting to review this PR. Can you swap mimic our for mox as this is our preferred mocking library

@TheFirstAvenger
Copy link
Member

To avoid changing application env vars on the fly, and also retain async on the tests, we should be able to set the :css_compiler mock in test.exs and then we can call the real Beacon.CSSCompiler directly in the test to test it. If we need to test it inline in another test, we can then @runtime_css and expect it in that specific test, maintaining async and with no env vars changing.

@ryanwinchester
Copy link
Contributor Author

ryanwinchester commented Oct 28, 2022

To avoid changing application env vars on the fly, and also retain async on the tests, we should be able to set the :css_compiler mock in test.exs and then we can call the real Beacon.CSSCompiler directly in the test to test it. If we need to test it inline in another test, we can then @runtime_css and expect it in that specific test, maintaining async and with no env vars changing.

Yeah, thanks. That's a lot better. I never use Mox because I don't like all the extra ceremonial code just to be able to write some tests, and was just following along with their docs.

@AZholtkevych AZholtkevych linked an issue Nov 22, 2022 that may be closed by this pull request
@AZholtkevych AZholtkevych removed a link to an issue Nov 22, 2022
@AZholtkevych AZholtkevych linked an issue Nov 22, 2022 that may be closed by this pull request
@AZholtkevych AZholtkevych removed a link to an issue Nov 22, 2022
@AZholtkevych AZholtkevych linked an issue Nov 22, 2022 that may be closed by this pull request
@AZholtkevych AZholtkevych removed a link to an issue Nov 22, 2022
@AZholtkevych AZholtkevych linked an issue Nov 22, 2022 that may be closed by this pull request
@AZholtkevych AZholtkevych removed a link to an issue Nov 22, 2022
@AZholtkevych AZholtkevych linked an issue Nov 22, 2022 that may be closed by this pull request
Copy link
Contributor

@leandrocp leandrocp left a comment

Choose a reason for hiding this comment

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

Hey @ryanwinchester an initial review to help getting the PR done.

/edit you could also add tailwind.install in the setup alias

beacon/mix.exs

Line 50 in 5a169f6

setup: ["deps.get", "ecto.setup"],

README.md Outdated Show resolved Hide resolved
lib/beacon/runtime_css.ex Outdated Show resolved Hide resolved
lib/beacon/css_compiler.ex Outdated Show resolved Hide resolved
config/dev.exs Show resolved Hide resolved
Switch to mox and add the required ceremonial code

Remove application env setting in test for CSS and Mox
@leandrocp
Copy link
Contributor

leandrocp commented Dec 16, 2022

Hey @ryanwinchester seems like it's missing the loading of runtime_css in root.html.heex. The beacon.css file is compiled and then injected into layout_assigns but seems like it's never loaded in the generated template. I was assuming it would be injected like the other components here:

<%= meta_tags(assigns) %>
<%= linked_stylesheets(assigns) %>
<%= stylesheet_tag(assigns) %>

@ryanwinchester
Copy link
Contributor Author

ryanwinchester commented Dec 16, 2022

Hey @ryanwinchester seems like it's missing the loading of runtime_css in root.html.heex.

@leandrocp Yeah I had mentioned in previous discussions that I was adding the compiled CSS to the assigns but didn't know where those were being used and how to get the CSS into the actual rendered layout, but never really got an answer. So, just assumed it would be resolved later 😂.

@leandrocp
Copy link
Contributor

Hey @ryanwinchester seems like it's missing the loading of runtime_css in root.html.heex.

@leandrocp Yeah I had mentioned in previous discussions that I was adding it to the assigns but didn't know where those were being used and how to get the CSS into the actual rendered layout, but never really got an answer. So, just assumed it would be resolved later 😂.

Ohh gotcha 😂
Yeah IMO that would be in root.html.heex but it's fine to add it in a following PR

Copy link
Contributor

@leandrocp leandrocp left a comment

Choose a reason for hiding this comment

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

I'm not sure about #30 (comment) but it LGTM.

Great work!

Co-authored-by: Leandro Pereira <leandro@leandro.io>
@leandrocp
Copy link
Contributor

Thanks!!

@leandrocp leandrocp merged commit 823cfa1 into BeaconCMS:main Dec 22, 2022
@ryanwinchester ryanwinchester deleted the feature/runtime-css-compile branch December 22, 2022 18:50
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.

Tailwind compilation
4 participants