Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

less-middleware

Package Overview
Dependencies
Maintainers
2
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

less-middleware - npm Package Compare versions

Comparing version 0.1.12 to 0.1.13

40

lib/middleware.js

@@ -0,1 +1,3 @@

"use strict";
/*!

@@ -13,2 +15,3 @@ * Less - middleware (adapted from the stylus middleware)

mkdirp = require('mkdirp'),
extend = require('node.extend'),
determine_imports = require('./determine-imports.js');

@@ -35,2 +38,4 @@

* `dumpLineNumbers` Add line tracking to the compiled css. ('comments' or 'mediaquery')
* `preprocessor` Function to transform input .less code before parsing,
* receives source code and Connect request object as parameters
*

@@ -83,3 +88,3 @@ * Examples:

console[type](' \033[90m%s :\033[0m \033[36m%s\033[0m', key, val);
console[type](" \u001b[90m%s :\u001b[0m \u001b[36m%s\u001b[0m", key, val);
}

@@ -130,3 +135,12 @@ };

options.dumpLineNumbers = options.dumpLineNumbers || 0;
// Preprocessor
options.preprocessor = options.preprocessor || function(src, req) { return src; };
// Relative paths?
options.relativeUrls = options.relativeUrls || false;
// Source map
options.sourceMap = options.sourceMap || false;
// Source dir required

@@ -139,2 +153,5 @@ var src = options.src;

// Allow root to redefine how paths are managed
var root = options.root || null;
if (options.paths){

@@ -158,3 +175,4 @@ if (!(options.paths instanceof Array)) {

optimization: options.optimization,
dumpLineNumbers: options.dumpLineNumbers
dumpLineNumbers: options.dumpLineNumbers,
relativeUrls: options.relativeUrls
});

@@ -170,3 +188,4 @@

compress: (options.compress == 'auto' ? regex.compress.test(cssPath) : options.compress),
yuicompress: options.yuicompress
yuicompress: options.yuicompress,
sourceMap: options.sourceMap
});

@@ -184,2 +203,5 @@

// Add tree functions if provided.
extend(less.tree.functions, options.treeFunctions || {});
// Middleware

@@ -204,2 +226,9 @@ return function(req, res, next) {

if (root) {
cssPath = path.join(root, dest, pathname.replace(dest, ''));
lessPath = path.join(root, src, pathname
.replace(dest, '')
.replace('.css', '.less'));
}
log('source', lessPath);

@@ -223,3 +252,4 @@ log('dest', cssPath);

try {
options.render(str, lessPath, cssPath, function(err, css){
var preprocessed = options.preprocessor(str, req);
options.render(preprocessed, lessPath, cssPath, function(err, css){
if (err) {

@@ -233,3 +263,3 @@ lessError(err);

mkdirp(path.dirname(cssPath), 0777, function(err){
mkdirp(path.dirname(cssPath), 511 /* 0777 */, function(err){
if (err) return error(err);

@@ -236,0 +266,0 @@

7

package.json

@@ -5,3 +5,3 @@ {

"description": "LESS.js middleware for connect.",
"version": "0.1.12",
"version": "0.1.13",
"repository": {

@@ -13,4 +13,5 @@ "type": "git",

"dependencies": {
"less": "~1.4",
"mkdirp": "~0.3"
"less": "~1.5",
"mkdirp": "~0.3",
"node.extend": "~1.0"
},

@@ -17,0 +18,0 @@ "devDependencies": {},

@@ -57,2 +57,7 @@ ## Installation

<tr>
<th><code>yuicompress</code></th>
<td>More involved minification with <a href="http://yui.github.io/yuicompressor/css.html">YUI compression</a></td>
<td><code>false</code></td>
</tr>
<tr>
<th><code>optimization</code></th>

@@ -63,7 +68,26 @@ <td>Desired level of LESS optimization. Optionally <code>0</code>, <code>1</code>, or <code>2</code></td>

<tr>
<th><code>dumpLineNumbers</th>
<th><code>dumpLineNumbers</code></th>
<td>Add line tracking to the compiled css. Optionally <code>0</code>, <code>'comments'</code>, or <code>'mediaquery'</code></td>
<td><code>0</code></td>
</tr>
<tr>
<th><code>relativeUrls</code></th>
<td>Adjust urls to be relative to directory of files imported with @import. If false, urls will remain unchanged.</td>
<td><code>false</code></td>
</tr>
<tr>
<th><code>sourceMap</code></th>
<td>Enable sourcemap support. You can compile your less and then use developer tools to see where in your less file a particular piece of css comes from.</td>
<td><code>false</code></td>
</tr>
<tr>
<th><code>preprocessor</code></th>
<td>Specify a preprocessing function applied to LESS source code before parsing. The function will receive the LESS source code and the Connect request object as parameters, and must return the modified source code.</td>
<td></td>
</tr>
<tr>
<th><code>treeFunctions</code></th>
<td>Object with custom functions added to <code>less.tree.functions</code>.</td>
<td></td>
</tr>
</tbody>

@@ -132,2 +156,24 @@ </table>

A new alternative way to achieve the same thing as using prefix but with greater flexibility is to supply a shared root value. From this shared root, you would specify a URI style path to the appropriate source and destination directories:
```javascript
var lessMiddleware = require('less-middleware')
, path = require('path')
, pubDir = path.join(__dirname, 'public')
, app = express.createServer();
app.configure(function() {
app.use(lessMiddleware({
dest: '/css', // should be the URI to your css directory from the location bar in your browser
src: '/less', // or '../less' if the less directory is outside of /public
root: pubDir,
compress: true
}));
app.use(express.static(pubDir));
});
```
This will allow any file under the /less directory, including subdirectories, to be compiled into an identical directory structure under /css.
### Express - Using a temp directory for `dest`

@@ -264,2 +310,26 @@

### Preprocessing
var lessMiddleware = require('less-middleware');
var app = express.createServer();
app.configure(function () {
// Other configuration here...
app.use(lessMiddleware({
src: __dirname + '/public',
preprocessor: function(src, req) {
if (req.param("namespace")) {
src = req.param("namespace") + " { " + src + " }";
}
return src;
},
compress: true
}));
app.use(express.static(__dirname + '/public'));
});
## Troubleshooting

@@ -278,1 +348,4 @@

```
### IIS
If you are hosting your app on IIS you will have to modify your `web.config` file in order to allow NodeJS to serve your CSS static files. IIS will cache your CSS files, bypassing NodeJS static file serving, which in turn does not allow the middleware to recompile your LESS files.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc