stylish
raw JSON → 1.0.0 verified Sat Apr 25 auth: no javascript
Stylus middleware for Connect/Express that compiles Stylus to CSS in memory without writing files to disk. Version 1.0.0 is the latest stable release, with no recent updates. It serves as a drop-in replacement for stylus.middleware(), offering optional compression, nib support, file change callbacks, and caching for production. Unlike the default Stylus middleware, it avoids disk writes and includes built-in file watching and dependency tracking.
Common errors
error Cannot find module 'stylish' ↓
cause Package not installed or not in node_modules
fix
npm install stylish
error stylish is not a function ↓
cause Attempted to use stylish as a constructor (e.g., new stylish()) or imported named instead of default
fix
Use 'import stylish from 'stylish'' and call as stylish({...})
Warnings
breaking Package version 1.0.0 has no breaking changes documented, but ensure stylus peer dependency >=0.40.0 or compilation may fail. ↓
fix npm install stylus@>=0.40.0
gotcha If cache option is true, file watching is disabled and CSS is cached in memory; changes to .styl files won't be picked up until server restart. ↓
fix Use cache: true only in production for performance; during development omit cache to enable live reload.
gotcha The package does not write compiled CSS to disk; ensure your app doesn't rely on static .css files being present on the filesystem. ↓
fix Serve CSS directly via middleware; do not expect .css files in the src directory.
Install
npm install stylish yarn add stylish pnpm add stylish Imports
- default wrong
const stylish = require('stylish')correctimport stylish from 'stylish' - stylish wrong
import { stylish } from 'stylish'correctimport stylish from 'stylish' - Middleware options wrong
const mw = new stylish()correctconst mw = stylish({ src: __dirname + '/public', compress: true })
Quickstart
import express from 'express'
import stylish from 'stylish'
import nib from 'nib'
const app = express()
const port = 3000
app.use(stylish({
src: __dirname + '/public',
compress: true,
setup: function(renderer) {
return renderer.use(nib())
}
}))
app.listen(port, () => {
console.log(`Server running on port ${port}`)
})