node-lessify
Advanced tools
Comparing version 0.0.5 to 0.0.6
76
index.js
@@ -1,7 +0,6 @@ | ||
// v0.0.4 | ||
// v0.0.6 | ||
var path = require("path"); | ||
var through = require('through2'); | ||
var less = require('less'); | ||
var CleanCSS = require('clean-css'); | ||
var through = require('through'); | ||
var path = require("path"); | ||
@@ -18,2 +17,15 @@ var textMode = false, | ||
/* | ||
you can pass options to the transform from your package.json file like so: | ||
"browserify": { | ||
"transform-options": { | ||
"node-lessify": "textMode" | ||
} | ||
} | ||
*/ | ||
/* | ||
textMode simply compiles the LESS into a single string of CSS and passes it back without adding the code that automatically appends that CSS to the page | ||
*/ | ||
if (options.browserify && options.browserify["transform-options"] && options.browserify["transform-options"]["node-lessify"] == "textMode") { | ||
@@ -27,35 +39,37 @@ textMode = true; | ||
} | ||
var buffer = "", | ||
mydirName = path.dirname(file); | ||
var parser = new(less.Parser)({ | ||
paths: [mydirName, __dirname], | ||
syncImport: true | ||
}); | ||
var buffer = "", mydirName = path.dirname(file); | ||
return through(function(chunk) { | ||
return buffer += chunk.toString(); | ||
}, function() { | ||
return through(write, end); | ||
var compiled; | ||
function write(chunk, enc, next) { | ||
buffer += chunk.toString(); | ||
next(); | ||
} | ||
// CSS is LESS so no need to check extension | ||
parser.parse(buffer, function(e, r) { | ||
compiled = r.toCSS(); | ||
}); | ||
function end(done) { | ||
var self = this; | ||
// rv comments | ||
// http://stackoverflow.com/questions/5989315/regex-for-match-replacing-javascript-comments-both-multiline-and-inline | ||
compiled = compiled.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:([\s;])+\/\/(?:.*)$)/gm, ""); | ||
try { | ||
// CSS is LESS so no need to check extension | ||
less.render(buffer, { | ||
paths: [".", mydirName], | ||
compress: true | ||
}, function(e, output) { | ||
compiled = output.css; | ||
if (textMode) { | ||
compiled = "module.exports = \"" + compiled.replace(/'/g, "\\'").replace(/"/g, '\\"') + "\";"; | ||
} else { | ||
compiled = func_start + "var css = \"" + compiled.replace(/'/g, "\\'").replace(/"/g, '\\"') + "\";" + func_end; | ||
} | ||
var compiled = CleanCSS().minify(compiled); | ||
if (textMode) { | ||
compiled = "module.exports = \"" + compiled.replace(/'/g, "\\'").replace(/"/g, '\\"') + "\";"; | ||
} else { | ||
compiled = func_start + "var css = \"" + compiled.replace(/'/g, "\\'").replace(/"/g, '\\"') + "\";" + func_end; | ||
} | ||
this.queue(compiled); | ||
return this.queue(null); | ||
}); | ||
self.push(compiled); | ||
self.push(null); | ||
done(); | ||
}); | ||
} catch (error) { | ||
self.emit('error', (error instanceof Error) ? error : new Error(error)); | ||
done(); | ||
} | ||
} | ||
}; |
{ | ||
"name": "node-lessify", | ||
"version": "0.0.5", | ||
"description": "LESS precompiler and CSS plugin for Browserify v2", | ||
"version": "0.0.6", | ||
"description": "LESS precompiler and CSS plugin for Browserify", | ||
"main": "index.js", | ||
@@ -26,8 +26,7 @@ "scripts": { | ||
"dependencies": { | ||
"through": "^2.2.7", | ||
"less": "^1.5.0", | ||
"clean-css": "2.0.2" | ||
"through2": "0.6.x", | ||
"less": "2.0.x" | ||
}, | ||
"devDependencies": { | ||
"browserify": "^6.0.0" | ||
"browserify": "6.x.x" | ||
}, | ||
@@ -34,0 +33,0 @@ "bugs": { |
node-lessify | ||
============ | ||
Version 0.0.5 | ||
Version 0.0.6 | ||
[![Build Status](https://travis-ci.org/wilson428/node-lessify.png)](https://travis-ci.org/wilson428/node-lessify) | ||
LESS precompiler and CSS plugin for Browserify v2. Inspired by [node-underscorify](https://github.com/maxparm/node-underscorify). | ||
LESS 2.0 precompiler and CSS plugin for Browserify v2. Inspired by [node-underscorify](https://github.com/maxparm/node-underscorify). | ||
@@ -9,0 +9,0 @@ When bundling an app using [Browserify](http://browserify.org/), it's often convenient to be able to include your CSS as a script that appends the style declarations to the head. This is particularly relevant for self-assembling apps that attach themselves to a page but otherwise have reserved real-estate on the DOM. |
@@ -1,3 +0,5 @@ | ||
var css = require("./styles.css"); | ||
var css = require("../styles.css"); | ||
var less = require("../styles.less"); | ||
console.log(css); | ||
console.log(css); | ||
console.log(less); |
@@ -11,5 +11,5 @@ #!/usr/bin/env node | ||
var b = browserify(); | ||
b.add(sampleLESS); | ||
b.add(sampleCSS); | ||
var b = browserify(sampleLESS); | ||
//b.add(sampleLESS); | ||
//b.add(sampleCSS); | ||
b.transform(lessify); | ||
@@ -19,5 +19,7 @@ | ||
if (err) { | ||
console.error(err); | ||
assert.fail(err); | ||
} | ||
assert.ok(src); | ||
fs.writeFileSync(__dirname + "/bundle.js", src.toString()); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8333
2
86
14
+ Addedthrough2@0.6.x
+ Addedasap@1.0.0(transitive)
+ Addedbl@0.9.5(transitive)
+ Addedcaseless@0.6.0(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedless@2.0.0(transitive)
+ Addedoauth-sign@0.4.0(transitive)
+ Addedpromise@6.0.1(transitive)
+ Addedqs@2.3.3(transitive)
+ Addedreadable-stream@1.0.34(transitive)
+ Addedrequest@2.47.0(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedthrough2@0.6.5(transitive)
+ Addedxtend@4.0.2(transitive)
- Removedclean-css@2.0.2
- Removedthrough@^2.2.7
- Removedclean-css@2.0.22.2.23(transitive)
- Removedcommander@2.0.02.2.0(transitive)
- Removedless@1.7.5(transitive)
- Removedoauth-sign@0.3.0(transitive)
- Removedqs@1.0.2(transitive)
- Removedrequest@2.40.0(transitive)
- Removedthrough@2.3.8(transitive)
Updatedless@2.0.x