Eleventy Plugin Baseline

A magic carpet ride

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

Steps

  1. Install PostCSS and the plugins you plan to use:

    npm install postcss postcss-import postcss-preset-env cssnano postcss-mixins

    Baseline ships fallback plugins, but when you provide your own postcss.config.js, bring the plugins as explicit dependencies.

  2. Add postcss.config.js at 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
    };
  3. 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";
  4. 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.

Notes

Previous: Social Previews Checklist

Next: Custom Esbuild Targets