Documentation — Table of Contents
Custom PostCSS Config
Provide your own postcss.config.js to override Baseline’s fallback. Keep cssnano for production only, add or remove plugins as needed, and verify the output.
Prerequisites
- Baseline installed and loaded; assets pipeline enabled.
src/assets/css/index.cssexists as the entry.package.jsonwith"type": "module"and scripts (dev,build).
Steps
-
Install PostCSS and the plugins you plan to use:
npm install postcss postcss-import postcss-preset-env cssnano postcss-mixinsBaseline ships fallback plugins, but when you provide your own
postcss.config.js, bring the plugins as explicit dependencies. -
Add
postcss.config.jsat the project root:import postcssImport from "postcss-import"; import postcssMixins from "postcss-mixins"; import postcssPresetEnv from "postcss-preset-env"; import cssnano from "cssnano"; const isProd = process.env.ELEVENTY_ENV === "production"; const plugins = [ postcssImport(), postcssMixins(), postcssPresetEnv({ stage: 1 }), ]; if (isProd) { plugins.push(cssnano({ preset: "default" })); } /** @type {import('postcss-load-config').Config} */ export default { map: isProd ? false : { inline: true }, plugins }; -
Exercise the config in your CSS (imports and mixins):
src/assets/css/base.css::root { color-scheme: light; } body { font-family: system-ui, sans-serif; margin: 0; padding: 2rem; line-height: 1.5; color: #1f2937; background: #f8fafc; } h1 { margin-bottom: 0.5rem; } .pill { display: inline-block; padding: 0.25rem 0.75rem; border-radius: 999px; background: #e0f2fe; color: #0f172a; font-weight: 600; }src/assets/css/mixins.css:@define-mixin linksMixin { color: #0f172a; text-decoration: underline; text-decoration-color: #fc35b9; text-decoration-thickness: 2px; text-underline-offset: 3px; font-weight: 600; }src/assets/css/links.css:a { @mixin linksMixin; } a:hover { color: #fc35b9; }src/assets/css/index.css:@import "./base.css"; @import "./mixins.css"; @import "./links.css"; -
Run and inspect.
- Dev:
npx rimraf dist/ && npm run dev - Build:
npx rimraf dist/ && npm run build - Check
dist/assets/css/index.css:- Dev: expanded CSS with mapped imports; no minification.
- Prod: minified (cssnano), imports flattened, custom media resolved.
- Dev:
Notes
- Your
postcss.config.jsfully overrides Baseline’s fallback. Keep the entry file atsrc/assets/css/index.css; add partials via imports. - Add/remove plugins as needed (e.g., purge/RTL/lightningcss). Use env guards to keep dev output readable and prod output optimized.
Previous: Social Previews Checklist
Next: Custom Esbuild Targets