@chuchur/koa-less

Less middleware for Koa

Usage no npm install needed!

<script type="module">
  import chuchurKoaLess from 'https://cdn.skypack.dev/@chuchur/koa-less';
</script>

README

Sorry , koa-less moudle is invalid, please use koa-minify

Installation

npm install @chuchur/koa-minify --save

Usage

...
 
const koaMinify = require('@chuchur/koa-minify')
const serve = require('koa-static');

//will compress js and build less
koaMinify(staticPath,cssOptions,jsOptions )


//static
app.use(serve(__dirname + '/public'));
 
app.listen(3000);

staticPath

The static resource directory

cssOptions

{
  entry: 'entry: __dirname + '/public/less/index.less',
  output: 'entry: __dirname + '/public/css/index.css',
  options:{} //more http://lesscss.org/usage/#less-options
}

jsOptions

{
  minify: true, //default false
  options:{} //more https://github.com/mishoo/UglifyJS2#command-line-options
}

Demo


app
 |--public
 |   |--less
 |        |--header.less
 |        |--footer.less
 |        |--common.less
 |        |--index.less
 |   |--css
 |   |--js
 |       |--utils.js
 |       |--common.js
 |   |--fonts
 |   |--img
 |--src
 |   |--controller
 |   |--views
 |--app.js

//app.js
const koaMinify = require('@chuchur/koa-minify')
const serve = require('koa-static');

koaMinify(__dirname + '/public',
  {
    entry: __dirname + '/public/less/index.less',
    output: __dirname + '/public/css/index.css'
  },
  {
    minifiy:true 
  } 
)


//static
app.use(serve(__dirname + '/public'));
 
app.listen(3000);

// public/less/index.less
@import header.less
@import footer.less
@import common.less



/*

change file  one of endwith '.less' will be auto build and output '/public/css/index.css'

change '/public/js/utils.js'  ,will output '/public/js/utils.min.js' ,please sure : { minifiy:true }

*/

If app run by nodemon , please add nodemonConfig to the package.json , nodemon watch all the JS file

//package.json

"nodemonConfig": {
  "ignore": [
    "public/js/*"
  ]
}