postcss-watcher

2.0.0 • Public • Published

postcss-watcher 👀

npm version build status downloads style

Watches files in PostCSS bundle and emits events on change.

Usage

Create an instance of the Watcher and use the watcher.plugin function as you would any other plugin. It is recommended to put the watcher plugin as the last plugin to ensure that all files are being watched.

var fs = require('fs')
var postcss = require('postcss')
var atImport = require('postcss-import')
var Watcher = require('postcss-watcher')
 
var watcher = new Watcher()
var bundle = postcss([atImport() watcher.plugin()])
 
watcher.on('change', process)
process()
 
function process () {
  bundle.process(fs.readFileSync('./index.css', 'utf8'), {
    from: __dirname + '/index.css'
  }).then(function (result) {
    fs.writeFileSync(__dirname + '/build.css'), result.css)
  })
}

API

watcher = new Watcher([opts])

Create an instance of Watcher. Forwards opts to chokidar and ignores files in node_modules by default. Watcher is a subclass of chokidar, so all the same events are supported (ready, add, change, unlink, all etc.).

watcher.plugin()

Returns a PostCSS plugin function.

watcher.prune(fn)

Remove listeners for files that pass the supplied filter function test. The supplied function is called for every file being watched with the file path as only argument. Expects a Boolean to be returned.

Install

$ npm install -S postcss-watcher

License

MIT

Package Sidebar

Install

npm i postcss-watcher

Weekly Downloads

19

Version

2.0.0

License

MIT

Unpacked Size

8.48 kB

Total Files

5

Last publish

Collaborators

  • antontrollback
  • tornqvist