/process-css

A CSS processor with a simple plugin design that can process CSS server-side and client-side into CSS, JS, and other file output

Primary LanguageJavaScriptMIT LicenseMIT

process-css

A CSS processor with a simple plugin design that can process CSS server-side and client-side into CSS, JS, and other file output

Usage

This package is delivered in CJS format and an ES module.

CJS version: Node and as a browser script

// Node
const processCSS = require('../index.cjs.js')
<!-- browser script -->
<script src=../index.cjs.js></script>

ES module version: Deno and as a browser module

// Deno
import processCSS from '../index.js'
<!-- browser module -->
<script type=module>
  import processCSS from '../index.js'
<script>

Syntax

process(stringOfCSS, listOfPlugins, environment)
  • stringOfCSS is a string containing a CSS stylesheet - one or more rules
  • listOfPlugins is an array of process-css plugin functions
  • environment is an optional object that may include any data you want to make available to the plugins in the listOfPlugins as they process the stringOfCSS

process-css plugin function format

function(string, environment) {

  return {
    css: '',
    js: '',
    otherFiles: {}
  }
}
  • every process-css plugin is a function that accepts a string, this is either the input CSS if this is the first plugin in the listofPlugins to be processed, or will be given the previous plugin's result.css from the return object of the previously run plugin as its input

  • every process-css plugin may optionally accept an object containing any data or values you want available to the plugin while it does its transformation

  • every process-css plugin returns an object optionally containing:

    • a css property with a string of CSS to pass to the next plugin in the listOfPlugins or as the final output if it's the last plugin to be processed.
    • a js property with a string of JavaScript to accumulate any JavaScript output that is generated by your plugins
    • a otherFiles object which contains key/value pairs where the keys represent filenames of additional files you want to output, and the value contains the text content of those files