145
loading...
This website collects cookies to deliver better user experience
npm
or yarn
dependency.npm i -g tailwindcss
yarn global add tailwindcss
tailwindcss --help
PATH
properly for global installs by either NPM or Yarn (particularly Yarn...).index.html
for Trunk:tailwindcss -o ./tailwind.css
tailwind.css
that contains around 4MB of pure CSS. We'll come back to cutting that down. For now though, you should make sure that doesn't get added to version control by adding it your .gitignore
like so:tailwind.css
index.html
, which we can do by adding this to the head:<link data-trunk href="./tailwind.css" rel="css" />
html!
, try it out like this:html! {
<p class=classes!("bg-red-100")>{"Test!"}</p>
}
trunk serve
, you should see a paragraph saying Test with a very light red background! Congratulations, you've set up Tailwind with Yew in development!tailwind.config.js
file at the root of your project and add this to it:module.exports = {
purge: {
mode: "all",
content: [
"./src/**/*.rs",
"./index.html",
"./src/**/*.html",
"./src/**/*.css",
],
},
theme: {},
variants: {},
plugins: [],
};
src/
and remove any classes it doesn't find being used there. We also check index.html
in case you have anything in there. This check could probably be refined using the extract
property so it only checks Rust files in html!
, but this is good enough for now.NODE_ENV=production tailwindcss -c ./tailwind.config.js -o ./tailwind.css --minify
tailwind.css
file. It should be something like 3KB! That's a pretty giant improvement!build
and run
. Check out the Bonnie wiki for an explanation of how this example file works (should be pretty self-explanatory though):version="0.3.1"
[scripts]
## Builds Tailwind CSS for development (no purging)
build-tailwind-dev = [
"cd frontend",
"tailwindcss -c ./tailwind.config.js -o ./tailwind.css"
]
## Builds Tailwind CSS for production (maximum purging and minification)
build-tailwind-prod = [
"cd frontend",
"NODE_ENV=production tailwindcss -c ./tailwind.config.js -o ./tailwind.css --minify"
]
## Builds Tailwind CSS for development usage
setup.subcommands.tailwind = "bonnie build-tailwind-dev"
setup.subcommands.prompt-tailwind = "echo \"Have you installed the Tailwind CLI globally with 'npm i -g tailwindcss' or 'yarn global add tailwindcss'?\""
setup.order = """
tailwind {
Failure => prompt-tailwind
}
"""
## Builds everything
build.cmd = "cargo build"
## Builds the frontend
build.subcommands.frontend = [
"cd frontend",
"bonnie build-tailwind-prod",
"cargo build"
]
## Runs the frontend, watching for changes (uses Trunk)
## Tailwind is assumed to be set up after `setup`
run.subcommands.frontend = [
"cd frontend",
"trunk serve"
]
bonnie setup
to build Tailwind for them! Running bonnie run frontend
will spin up a Trunk server for you automatically, and bonnie build frontend
will build everything for production (including Tailwind)! Note that this configuration assumes you've got everything in frontend/
in case you've got a backend/
as well (if not you can just remove those bits).