Created
April 3, 2023 19:24
-
-
Save rhoover/7a57e18d696717fe1bd9f5d08a0b787a to your computer and use it in GitHub Desktop.
Eleventy Force Reload For Inlined CSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Let's say you have a head-element.njk template. There, or wherever your <head> element is, place: | |
<!-- critical styles --> | |
{% set critical %} | |
{% include "../../critical/critical.css" %} | |
{% endset %} | |
<style> | |
{{ critical | safe }} | |
</style> | |
And in your package.json, do this: | |
"watch:critical": "sass --style compressed --no-source-map --watch src/sass/critical.scss:src/critical/critical.css", | |
"watch:eleventy": "rm -rf dist && npx @11ty/eleventy --serve", | |
"serve": "npm-run-all --parallel watch:eleventy watch:critical" | |
And presto! Any saved changes to your critical-CSS .scss files are captured and re-rendered on the screen. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment