Skip to content

codeandconspire/koa-postcss-watch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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

About

Koa middleware for processing css on the fly πŸ“

Resources

Stars

Watchers

Forks

Packages

No packages published