Registry / devops / less-cache

less-cache

JSON →
library1.1.1jsnpmunverified

A Node.js library that compiles Less files and caches the resulting CSS. Version 1.1.1 is the last release; the project is in maintenance mode. It wraps the Less compiler with a simple disk cache (configurable directory) to speed up repeated compilations. Unlike webpack loaders or Gulp plugins, this is a standalone utility for one-off compilation with caching. It only provides synchronous readFileSync API. No longer actively developed by the Atom editor team.

npm install less-cache
INSTALL
IMPORT
SIG · LESS-CACHE
L
less-cache
devopsjavascriptv1.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LessCache
const LessCache = require('less-cache')
import LessCache from 'less-cache'
Package uses CommonJS, not ES modules. ESM import will fail.
new LessCache(options)
const cache = new LessCache({ cacheDir: '/tmp/less-cache' })
const cache = LessCache({ cacheDir: '/tmp/less-cache' })
LessCache must be instantiated with 'new'. Forgetting 'new' causes TypeError.
cache.readFileSync(path)
const css = cache.readFileSync('/path/to/style.less')
cache.readFile('/path/to/style.less', (err, css) => {})
Only synchronous API available. No async variant.

Creates a LessCache instance with a custom cache directory and compiles a .less file synchronously.

const LessCache = require('less-cache'); const path = require('path'); const cacheDir = path.join(__dirname, '.less-cache'); const cache = new LessCache({ cacheDir }); // Path to your .less file const lessFile = path.join(__dirname, 'styles.less'); // Compile and cache; returns CSS string const css = cache.readFileSync(lessFile); console.log(css); // Subsequent calls use cache unless .less file changes const cachedCss = cache.readFileSync(lessFile); console.log('Cached:', cachedCss === css);
Debug
Known issues
breakingThe `cacheDir` option is required.
fix
Always provide `cacheDir` in constructor options.
affects: >=0.0.0
gotchaOnly synchronous API available; throws if file not found or compilation error.
fix
Wrap calls in try/catch or use async wrappers (unoffical).
affects: >=0.0.0
deprecatedPackage is no longer actively maintained by Atom. Last release 1.1.1 (2016).
fix
Consider alternatives like less-loader, gulp-less, or postcss with caching.
affects: >=0.0.0
gotchaCaching is based on file modification time; may not detect all changes (e.g., imports).
fix
Manually clear cache or use import-aware caching.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: LessCache is not a constructor
Forgot 'new' when instantiating LessCache.
fix
Use `new LessCache({...})`.
Error: Cannot find module 'less'
Missing peer dependency 'less'.
fix
Run `npm install less` in your project.
ENOENT: no such file or directory, open '...'
Provided .less file path does not exist.
fix
Ensure the file path is correct and accessible.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
lessrequiredPeer dependency for Less compilation
mkdirprequiredCreates cache directory recursively
Agent activity
2 hits · last 30 days
node
2
Resources
less-cache — npm install less-cache · libregistry