PostCSS & Tailwind

PostCSS

PostCSS transforms CSS through plugins. For example, a plugin can add browser-specific prefixes or expand syntax before the stylesheet reaches the browser.

PostCSS support is handled as a buildtime plugin with Mountaineer. It's disabled by default. To enable, make sure you have postcss-cli installed within your views project:

npm install postcss-cli

Register PostCSSBundler in the application's build pipeline:

from mountaineer.client_compiler.postcss import PostCSSBundler

controller = AppController(
    custom_builders=[
        PostCSSBundler(),
    ],
)

PostCSSBundler finds CSS files in views and passes them through PostCSS. For example:

/views/app/home/style.css
/views/app/detail/style.css

The compiled stylesheets are written to:

/views/_static/home_style.css
/views/_static/detail_style.css

Load the stylesheet through a <link> in your page or global metadata. See the metadata documentation for the syntax.

Tailwind

The Tailwind configuration below uses PostCSS to generate styles for the classes found in your view files. See Tailwind's setup guide for installation details.

// views/app/tailwind.config.ts
module.exports = {
  content: ["./app/**/*.{html,tsx,jsx,ts,js}"],
  theme: {
    extend: {},
  },
  plugins: [],
}
/* views/app/main.css */
@tailwind base;
@tailwind components;
@tailwind utilities;

Then export the built styles into your global metadata:

controller = AppController(
    config=AppConfig(),
    global_metadata=Metadata(
        links=[LinkAttribute(rel="stylesheet", href="/static/app_main.css")]
    ),
    custom_builders=[
        PostCSSBundler(),
    ],
)