require-less
Experimental
Browserify transform to require('file.less')
and output the compiled css into a file.
Whats different about this Browserify less transform?
The rest of Css and Less Browserify transforms point to
head;
This transform will generate a stream with your compiled css and an interface to piping transforms into it so you can do what every you like.
Example
// index.js
/* style.less */
will generate a separate bundle file compiled.css
/* compiled.css */
👍
What require-less can do for you
require('file.css')
andrequire('file.less')
will work!- Works with both
css
andless
- You still have complete less and css functionality like
@import
- It will create a stream that contains the compiled css and then you can do whatever you like with it! (see
pipe
method)
Example
This is my recommended way of outputing the compiled css into a file, but you can also use
fs.createWriteStream('path/compiled.css')
and of course any other analogues.
var gulp = ;var source = ; var require_less = pipe: gulp ;
In the preceding example the vinyl-source-stream
library is being used to turn
the regular stream to something gulp can handle.
This illustrates that you can use the pipe attribute to pipe any stream transform providing complete freedom for what you want to do.
test/test_case_3.js
is a test using a 2 gulp plugins: gulp-rev
and gulp-buffer
.
API
require('require_less')(options)
It will return a transform function ready to be used by browserify.
var require_less = options ;
browserify_opts
its just regular browserify opts
options
Options will host all the regular less parser options plus some useful attributes as detailed below.
options.pipe
This attribute provides an interface to deal with the css stream as you will regularly
do with read_stream.pipe(transform_stream);
.
The pipe array will be executed in order in the following way:
css_stream ... ;
options.cb
Provide a callback that will be executed at the end of the stream transform process.
Test it!
Checkout travis.ci badge, or run locally the tests by
cd path/to/repo/rootnpm test
Notes
- This transform will not work when setting
browserify.transform
inpackage.json
due to its nature. - This transform does not work with Watchify yet, pull request welcome.
Thanks to
The following are links to sources of inspiration and conflict solving when I was working on this Transform. I have copied pieces of code from them so they are contributors.