koa-postcss-watch

1.0.5 • Public • Published

koa-postcss-watch 🏓

npm version build status downloads style

Be lazy. Watch and process css on the fly with PostCSS.

Usage

var Koa = require('koa')
var mount = require('koa-mount')
var watch = require('koa-postcss-watch')
var app = new Koa()
 
if (process.env.NODE_ENV === 'development') {
  app.use(mount('/bundle.css', watch({
    file: 'lib/index.css',
    plugins: [require('postcss-import'), require('autoprefixer')]
  })))
}
 
app.use(function (ctx) {
  ctx.body = `
    <!doctype html>
    <html>
    <head>
      <meta charset="utf-8">
      <link rel="stylesheet" href="/bundle.css">
    </head>
    <body>
      Hello world
    </body>
    </html>
  `
})
 
app.listen(process.env.PORT)

API

watch([opts])

Create a middleware function. If opts.file is not defined, path to file will be resolved to ctx.path relative to opts.root or process.cwd().

Options

Options are forwarded to both chokidar and postcss.

  • file <string> CSS entry file
  • root <string> Path from which to resolve file paths (defaults to cwd)
  • plugins [<string>] List of plugins to use with postcss

Install

$ npm install -S koa-postcss-watch

License

MIT

Package Sidebar

Install

npm i koa-postcss-watch

Weekly Downloads

6

Version

1.0.5

License

MIT

Last publish

Collaborators

  • antontrollback
  • tornqvist