#tailwind #macro #env-var #relative-path #web-server

macro tailwindcss-native-rust-macro

Generate tailwind output as a literal string at compile time

1 unstable release

0.1.0 Apr 22, 2024

#5 in #tailwindcss

MIT/Apache

14KB
280 lines

The include_tailwind! macro expects to be passed a set of arguments that will govern how it behaves. The expected format is as follows:

include_tailwind! {
    config: "path/to/tailwind.config.js",
    input: "path/to/tailwind.input.js",
    tailwindcss_bin: "/path/to/tailwindcss/bin/tailwindcss"
}

If a relative path is given, it will be taken relative to the CARGO_MANIFEST_DIR.

The macro will then compile to an inline string representing the output from tailwindcss. This can then be embeded in and returned by (with necessary CSS headers) your web server framework of choice.

If any of the arguments are not present, they will be read from a corresponding environment variable:

  • TAILWINDCSS_CONFIG
  • TAILWINDCSS_INPUT
  • TAILWINDCSS_BIN

If you would like to override the environment variable being read from, you may do that with the _env parameters.

include_tailwind! {
    config_env: "MY_TAILWINDCSS_CONFIG_ENV_VAR",
    input_env: "MY_TAILWINDCSS_INPUT_ENV_VAR",
    tailwindcss_bin: "MY_TAILWINDCSS_BIN_ENV_VAR"
}

Dependencies

~315–770KB
~18K SLoC