Code Monkey home page Code Monkey logo

less.js-middleware's Introduction

This middleware was created to allow processing of Less files for Connect JS framework and by extension the Express JS framework.

CircleCI Dependency Status

Installation

npm install less-middleware --save

Usage

lessMiddleware(source, [{options}])

Express

var lessMiddleware = require('less-middleware');

var app = express();
app.use(lessMiddleware(__dirname + '/public'));
app.use(express.static(__dirname + '/public'));

options

The following options can be used to control the behavior of the middleware:

Option Description Default
debug Show more verbose logging? false
dest Destination directory to output the compiled .css files. Same directory as less source files.
force Always re-compile less files on each request. false
once Only recompile once after each server restart. Useful for reducing disk i/o on production. false
pathRoot Common root of the source and destination. It is prepended to both the source and destination before being used. null
postprocess Object containing functions relevant to postprocessing data.
postprocess.css Function that modifies the compiled css output before being stored. function(css, req){...}
preprocess Object containing functions relevant to preprocessing data.
preprocess.less Function that modifies the raw less output before being parsed and compiled. function(src, req){...}
preprocess.path Function that modifies the less pathname before being loaded from the filesystem. function(pathname, req){...}
preprocess.importPaths Function that modifies the import paths used by the less parser per request. function(paths, req){...}
render Options for the less render. See the "render Options" section below. โ€ฆ
storeCss Function that is in charge of storing the css in the filesystem. function(pathname, css, req, next){...}
cacheFile Path to a JSON file that will be used to cache less data across server restarts. This can greatly speed up initial load time after a server restart - if the less files haven't changed and the css files still exist, specifying this option will mean that the less files don't need to be recompiled after a server restart.

render Options

The options.render is passed directly into the less.render with minimal defaults or changes by the middleware.

The following are the defaults used by the middleware:

Option Default
compress auto
yuicompress false
paths []

Examples

Common examples of using the Less middleware are available in the wiki.

Troubleshooting

My less never recompiles, even when I use {force: true}!

Make sure you're declaring less-middleware before your static middleware, if you're using the same directory, e.g. (with express):

var lessMiddleware = require('less-middleware');

var app = express();
app.use(lessMiddleware(__dirname + '/public'));
app.use(express.static(__dirname + '/public'));

not

var lessMiddleware = require('less-middleware');

var app = express();
app.use(express.static(__dirname + '/public'));
app.use(lessMiddleware(__dirname + '/public'));

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.

less.js-middleware's People

Contributors

0b10011 avatar courajs avatar daemonl avatar danielhusar avatar edy avatar emecell avatar federicobond avatar grahamb avatar hazukishiro avatar hdanak avatar jbuck avatar johngeorgewright avatar jorundur avatar k88hudson avatar kaareal avatar kamikat avatar kersten avatar laveklint avatar meatcar avatar mihail-alexe-nutanix avatar namuol avatar nchase avatar neekey avatar nyteshade avatar paton avatar pdehaan avatar rush avatar taxilian avatar viveksjain avatar zoramite avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

less.js-middleware's Issues

Failure on First Request, and No Recompilation

I've set up less.js-middleware in the usual way (particularly, with the stock application created by express -c less), and created a simple LESS file called foo.less.

First request gives a 404.

$ curl http://localhost:3000/foo.css
Cannot GET /foo.css

Second request serves the compiled CSS.

$ curl http://localhost:3000/foo.css
body {
  color: red;
}

Change the color to blue, then reissue the request.

$ curl http://localhost:3000/foo.css
body {
  color: red;
}

Get the same output. This happens even when force is set to true. Using less-middleware 0.1.9.

Send {strictMath: true} to compiller

Hello, I just updated to 0.1.12 (1.4.0) and my code (and other libs code) broken because
font: 16px/30px Arial; becomes font: 0.533px Arial;
I need to pass option strictMath: true, but how can I do this?

Multiple "src" paths

Hello,
I need to set multiple "src" paths, but this option accepts only string values. Is something wrong with calling less-middleware multiple times with "app.use()" of "Express" (each time with different "src" path)? This is what I'm doing now and it's working.

TypeError: Arguments to path.join must be strings

Hi,
I updated all my modules to the latest and still got this error:

TypeError: Arguments to path.join must be strings

My package.json:

{
"name": "chapter1",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "3.4.7",
"hjs": "",
"less-middleware": "
"
}
}

I checked the less-middleware version and it is 0.2.0-beta.

The error trace:

TypeError: Arguments to path.join must be strings
at f (path.js:204:15)
at Object.filter (native)
at Object.exports.join (path.js:209:40)
at Object.handle (C:\workspace-nodejs\chapter1\node_modules\less-middleware\lib\middleware.js:128:26)
at next (C:\workspace-nodejs\chapter1\node_modules\express\node_modules\connect\lib\proto.js:193:15)
at pass (C:\workspace-nodejs\chapter1\node_modules\express\lib\router\index.js:113:24)
at Router._dispatch (C:\workspace-nodejs\chapter1\node_modules\express\lib\router\index.js:176:5)
at Object.router (C:\workspace-nodejs\chapter1\node_modules\express\lib\router\index.js:36:10)
at next (C:\workspace-nodejs\chapter1\node_modules\express\node_modules\connect\lib\proto.js:193:15)
at Object.methodOverride [as handle](C:workspace-nodejschapter1node_modulesexpressnode_modulesconnectlibmid
dlewaremethodOverride.js:48:5)

determine-imports uses synchronous fs calls

I completely forgot that I was originally going to refactor this to async fs calls. Since this only happens once per recompile, it might not be an issue--but I'll do the refactor if anyone wants it.

Require css from subfolder

My project looks like this:

/styles/index.less
index.html
index.js

When I ask for /styles/index.css the log of lessMid returns me:

pathname : /css/index.css
source : d:\Users\name\Progetti\AXA-PrintOnDemand\api\styles\styles\index.less
destination : d:\Users\name\Progetti\AXA-PrintOnDemand\api\styles\styles\index.css

Why does it search the less file inside the styles/styles subfolder?

This is how I call the middleware

app.use(lessMiddleware(__dirname + "/styles", {debug: true}));
app.use(express.static(__dirname + "/styles"));

Thanks.

Recompile LESS on file write from client

I've got a scenario where I'm allowing a user to write back to the LESS file on the server. As far as I know, there's no way to recompile that LESS file out to CSS with less-middleware unless I reload the entire page - which I do not want to do.

Before switching from LESS to less-middlware, I was accomplishing this with less.refresh().

Can you offer any suggestions on how I might accomplish this?

Less-middleware fails to compile .less files if there are .css files in the directory

I was trying to make a basic setup of Node, Express (3.0.0beta) and Twitter Bootstrap and I had two .css files from bootstrap in my styles directory plus 'style.less' file that I wanted to compile. The output from debug was:

source : D:\dev\abc\public\styles\bootstrap.less
dest : D:\dev\abc\public\styles\bootstrap.css
read : D:\dev\abc\public\styles\bootstrap.less
source : D:\dev\abc\public\styles\bootstrap-responsive.less
dest : D:\dev\abc\public\styles\bootstrap-responsive.css
read : D:\dev\abc\public\styles\bootstrap-responsive.less

And it always always ignored style.less file in the same directory and never compiled it. Please not that bootstrap.less does not exist. Changing the extensions of bootstrap files to .less doesn't help.

paths

just updated from 1.9 to 1.10 and my paths parameter no longer worked.

multiple src dirs?

Couldn't find this in the readme, is there a way to specify multiple src dirs, for when a project has to mix in .less files from other sources?

Add function to alter settings after initiation.

Quite a few frameworks (such as Locomotive, and some homebrews) separate configuration into different files depending on the current NODE_ENV, however less-middleware can only be configured via the constructor.

If a function or other could be added that allows the middleware's options to be set post-initialisation, I believe it'd come in handy.

Maybe use RECESS?

https://github.com/twitter/recess

Recess is the less linter by twitter, and basically wraps less. Using recess would allow warnings/errors on style violations, which would be cool for dev.

Also compiling Bootstrap is only officially supported on recess.

Is there a way to pass a variable into my LESS file?..

I'm trying to figure out how to support versioned file paths - e.g. /img//image.png

I'm experimenting with this --> https://github.com/serby/versionator

You'll notice the examples demonstrate how a fn is defined and used in stylus.

Is there a way to do something similar w/ LESS & LESS Middleware?

The end-goal being something along the lines of:

// where @version is set from app.js /  the middleware config step.

.thing {
    background-image: url("/img/@{version}/image.png"); 
}

non_object_property_load error : Cannot read property 'rules' of undefined

After upgrading to node 0.10.1 I am getting this error when processing @import directives which refer .css files. It does not happen with .less files. I am using the latest master. Processing the same file with lessc works alright. Cheers.

LESS non_object_property_load error : Cannot read property 'rules' of undefined
LESS File : undefined undefined:undefined
TypeError: Cannot read property 'rules' of undefined
at module.exports.process_tree_node (/home/diego/code/mbc-playout/node_modules/less-middleware/lib/determine-imports.js:17:26)
at process_import_rule (/home/diego/code/mbc-playout/node_modules/less-middleware/lib/determine-imports.js:36:3)
at /home/diego/code/mbc-playout/node_modules/less-middleware/lib/determine-imports.js:23:5
at Array.forEach (native)
at module.exports.process_tree_node (/home/diego/code/mbc-playout/node_modules/less-middleware/lib/determine-imports.js:22:16)
at module.exports (/home/diego/code/mbc-playout/node_modules/less-middleware/lib/determine-imports.js:10:3)
at /home/diego/code/mbc-playout/node_modules/less-middleware/lib/middleware.js:168:31
at Object.Parser.parser.parse (/home/diego/code/mbc-playout/node_modules/less-middleware/node_modules/less/lib/less/parser.js:476:17)
at Object.options.render (/home/diego/code/mbc-playout/node_modules/less-middleware/lib/middleware.js:156:12)
at /home/diego/code/mbc-playout/node_modules/less-middleware/lib/middleware.js:214:21

CSS formatting

By default ( or setting compress:false; ), the user's .less file is reformatted into this format when the .css is compiled:

.class 1 {
key:value;
key:value;
}
.class 2 {
key:value;
key:value;
}

Regardless of the beginning formatting.
If the CSS in the .less file is 'inline CSS', when viewing the compiled .css file, it is outputted in the above formatting.

'Inline CSS' is:

.class1 { key:value; key:value; }
.class2 { key:value; key:value; }

  1. Please do not reformat the user's CSS preference when compiling the .css output.

Thanks, and great plugin!

Is it possible to compile 2+ different CSS from 2+ different LESS sources?

Is it possible to compile 2 or more different LESS styles to 2 or more different CSS styles with nodejs, express and less-middleware like this?

var less = require('less-middleware');
app.use(less({
    src: '/less',
    dest: '/css',
    pathRoot: path.join(__dirname, 'public'),
    compress: true
}));

where LESS and CSS would be

style-one.less -> style-one.css
style-two.less -> style-two.css

For example, you have web app with huge CSS file, but for certain pages like error or login page you need just few lines of CSS.

http://stackoverflow.com/questions/24222755/how-to-compile-2-different-less-styles-with-nodejs-express-and-less-middleware

Pass through Less options

Ability to completely pass through a set of less options without needing to manually add each new option to the middleware.

EX:

lessMiddleware({
    src: __dirname + '/public',
    lessOptions: {
      strictMath: true
    }
})

Doesn't compile unless CSS file doesn't exist.

I have created a barebones Express JS template using Web Matrix, installed less, installed less-middleware, and I declared my less-middleware before my express.static file declaration, and still less-middleware will not compile my LESS file unless the CSS file does not exist.

server.js

var lessMiddleware = require('less-middleware');

var express = require('express')
  , routes = require('./routes')
  , user = require('./routes/user')
  , http = require('http')
  , path = require('path');


var app = express();

app.configure(function(){
  app.use(lessMiddleware({
    src: __dirname + '/public',
    force: true,
    debug: true
  }));
  app.set('port', process.env.PORT || 3000);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(app.router);
  app.use(express.static(path.join(__dirname, 'public')));
});

app.configure('development', function(){
  app.use(express.errorHandler());
});

app.get('/', routes.index);
app.get('/users', user.list);

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

index.jade

extends layout

block content
  h1= title
  p Welcome to #{title}

layout.jade

doctype 5
html
  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
  body
    block content

style.less

@color: #4D926F;
@color2: white;
@color3: black;
body {
  background-color: @color;
}
h1 {
  color: @color2;
  border:  1px solid @color3;
}

Not sure what exactly I am doing wrong here, but I have been at it for the past few hours, and I am getting frustrated that the middleware only compiles whenever the CSS doesn't exist, even when force is set to true. I restart the server after making a change, I've shut down the server and restarted when I have made a change, and I have also waiting 10 minutes after making a change to the LESS file to try and refresh my page after restarting the server to see if it is a timing issue and no luck. Any thoughts?

Add ability to extend less

Hi,

For me less is missing some important features like generate random number, pick random from array etc..
I would like to have ability to extend less tree functions with my custom functions from the init config so I can use them witout modifing something inside node_modules.
Please let me know if I can submit a pull request with such a functionality.

Thanks.

Intermittent failure due to not importing dependency

Hi,

I have a common.less where .roundedCorners is defined:

.roundedCorners (@radius) {
  -webkit-border-radius: @radius;
  -moz-border-radius: @radius;
  border-radius: @radius;
}

I have someWidget.less file that imports common and then uses .roundedCorners:

@import "common";
...
.foo {
  position: absolute;
  display: inline;
  line-height: 12px;
  background-color: #B94A48;
  margin-left: -9px;
  margin-top: -7px;
  font-size: 9px;
  font-weight: bold;
  color: white;
  padding: 2px 5px;
  .roundedCorners(7px);
  z-index: 2;
}

Mostly this is fine, but sometimes we see this fail in our acceptance tests (which, in case it matters, uses PhantomJS) and, more rarely, also fails on our deployed servers. The error we see in our acceptance tests is:

  LESS Name error : .roundedCorners is undefined
  LESS File : C:\projects\myproject\server\public\less\someWidget.less 51:2
Error: Auditor.error() was called. Investigate and fix error: Error: .roundedCorners is undefined
    at Object.exports.FailOnErrorAuditor.error (C:\projects\myproject\test\acceptance\env.js:29:19)
    at Object.handle (C:\projects\myproject\server\myproject_modules\webServer\webApp.js:243:20)
    at next (C:\projects\myproject\server\node_modules\express\node_modules\connect\lib\proto.js:184:27)
    at next (C:\projects\myproject\server\node_modules\express\node_modules\connect\lib\proto.js:186:21)
    at next (C:\projects\myproject\server\node_modules\express\node_modules\connect\lib\proto.js:186:21)
    at next (C:\projects\myproject\server\node_modules\express\node_modules\connect\lib\proto.js:186:21)
    at next (C:\projects\myproject\server\node_modules\express\node_modules\connect\lib\proto.js:164:84)
    at next (C:\projects\myproject\server\node_modules\express\node_modules\connect\lib\proto.js:164:84)
    at next (C:\projects\myproject\server\node_modules\express\node_modules\connect\lib\proto.js:164:84)
    at next (C:\projects\myproject\server\node_modules\express\node_modules\connect\lib\proto.js:164:84)
    at next (C:\projects\myproject\server\node_modules\express\node_modules\connect\lib\proto.js:186:21)
    at module.exports.less.middleware.compile (C:\projects\myproject\server\node_modules\less-middleware\lib\middleware.js:218:24)
    at module.exports.less.middleware.options.render (C:\projects\myproject\server\node_modules\less-middleware\lib\middleware.js:172:11)
    at Object.less.Parser.parser.parse.finish [as _finish] (C:\projects\myproject\server\node_modules\less-middleware\node_modules\less\lib\less\parser.js:478:21)
    at Object.tree.importVisitor.visitImport._importer.push.subFinish [as _finish] (C:\projects\myproject\server\node_modules\less-middleware\node_modules\less\lib\less\import-visitor.js:56:47)
    at Object.tree.importVisitor.visitImport._importer.push.subFinish [as _finish] (C:\projects\myproject\server\node_modules\less-middleware\node_modules\less\lib\less\import-visitor.js:56:47)
    at Object.tree.importVisitor.run (C:\projects\myproject\server\node_modules\less-middleware\node_modules\less\lib\less\import-visitor.js:25:22)
    at tree.importVisitor.visitImport.visitArgs.visitDeeper (C:\projects\myproject\server\node_modules\less-middleware\node_modules\less\lib\less\import-visitor.js:63:34)
    at less.Parser.imports.imports.push (C:\projects\myproject\server\node_modules\less-middleware\node_modules\less\lib\less\parser.js:97:17)
    at C:\projects\myproject\server\node_modules\less-middleware\node_modules\less\lib\less\index.js:141:13
    at less.Parser.parser.parse.finish (C:\projects\myproject\server\node_modules\less-middleware\node_modules\less\lib\less\parser.js:478:21)
    at Object.less.Parser.parser.parse (C:\projects\myproject\server\node_modules\less-middleware\node_modules\less\lib\less\parser.js:486:17)
    at parseFile (C:\projects\myproject\server\node_modules\less-middleware\node_modules\less\lib\less\index.js:140:31)
    at fs.readFile (fs.js:176:14)
    at Object.oncomplete (fs.js:297:15)

Cannot @import files using LESS 1.4.x

Getting the following log output from less middleware:

LESS undefined error : Arguments to path.join must be strings
LESS File : undefined undefined:undefined

...along with this stack trace:

TypeError: Arguments to path.join must be strings
    at path.js:360:15
    at Array.filter (native)
    at Object.exports.join (path.js:358:36)
    at module.exports.locate (/..<snip>../node_modules/less-middleware/lib/determine-imports.js:43:32)

It looks like a breaking change introduced by the main LESS.js lib. LESS' parser returns a .tree object with a slightly different structure. Here's an example:

New structure:

rules: [
    path: {
        escaped: undefined,
        index: undefined,
        quote: "",
        value: "core/base.less"
    }
]

Old structure:

rules: [
    _path: {
        // as shown above
    },
    path: "core/base.less"
]

The "determine-imports" module is calling its .locate() fn with import_rule.path when it appears to want import_rule.path.value instead.

For now downgrading to LESS v1.3.3 gets me back on track

Hope it helps!
-matt

Less dependency version too permissive

The version specifier in package.json for less is too permissive and can cause issues if the latest upstream version of less is unstable. As of version 0.1.11 package.json specifies a dependency on less ">= 1.3.3". This allows 1.4.0 to be installed which is currently in beta and unstable.

For example the beta version fails to compile lines such as the following from bootstrap's mixin.less:

(~".span@{index}") { .span(@index); }

May I suggest changing the dependency to "1.3.x" so that only minor version increments are pulled down?

styles.less cant process "@import"

I am trying to compile less files from twitter bootstrap. I renamed bootstrap.less to style.less and moved the *.less into the same src directory.

I get no errors, just no compilation

UPDATE: This is working!

Better documentation for paths option

Right now there isn't much explanation for how the paths option works under the hood and what it should look like. I needed to root around in the source to figure it out. It can be especially confusing if you're importing less files from different folders.

`prefix` doesn't work in v0.2.1-beta

Hi,

prefix doesn't work in v0.2.1-beta

if if i specified it as css, i still have:

  source : /project_path/less/css/common.less
  dest : /project_path/css/css/common.css
  read : /project_path/less/css/common.less

but should be as it was before in v0.1.15:

  source : /project_path/less/common.less
  dest : /project_path/public/css/common.css
  read : /project_path/less/common.less

TypeError: Arguments to path.join must be strings

When I follow your example:

    app.use(lessMiddleware({
        src: __dirname + '/public',
        compress: true
    }));

I run into this error:

TypeError: Arguments to path.join must be strings at f (path.js:204:15) at Object.filter (native) at Object.exports.join (path.js:209:40) at Object.handle 

This boils down to this part of the code:

  options = extend(true, {
    debug: false,
    dest: source,
    force: false,
    once: false,
    pathRoot: null,
    postprocess: {
      css: function(css, req) { return css; }
    },
    preprocess: {
      less: function(src, req) { return src; },
      path: function(pathname, req) { return pathname; }
    },
    storeCss: function(pathname, css, next) {
      mkdirp(path.dirname(pathname), 511 /* 0777 */, function(err){
        if (err) return next(err);

        fs.writeFile(pathname, css, 'utf8', next);
      });
    }
  }, options || {});

options is of course not set (the default {} is used) and instead of the source the options object is used:

 { debug: false,
  dest:
   { src: 'foo/bar',
     dest: 'foo/bax',
     force: true,
     compress: false,
     debug: true,
     prefix: '/css' },
  force: false,
  once: false,
  pathRoot: null,
  postprocess: { css: [Function] },
  preprocess: { less: [Function], path: [Function] },
  storeCss: [Function] }

this in turn messes up the configuration.

Importing font-awesome package breaks fonts

Hi,
I try to import font-awesome npm package, using

paths: [path.join(__dirname, 'node_modules', 'font-awesome', 'less')],
relativeUrls: true

and still fonts are broken. Just displaying squares.
It searches for font in noder_modules/font-awesome/fonts, but it doesn't find it, since it isn't published by server. How to fix that issue?

Use the useragent, as a variable within the compilation

Among browsers, there is much difference in a can change in a couple of pixels or the css3. If mounted in a variable as default useragent, The call stack can change the css for each browser.

@ua-browser : 'webkit'; // Or 'firefox', 'opera'... etc
@ua-version : 18.0 // The version

In the file

.truth (@ua-browser )  when (@ua-browser = 'firefox') { 
//Your code :)
}

And it becomes more dynamically the css

Unit Tests

Currently there are no unit tests which makes me apprehensive. Need to add in unit test, maybe rework some of the logic at the same time to make it easier to use and pass through variables to LESS.

Difficulty with source maps

I've tried every combination of options I can think of, but my CSS always generates the sourcemap "inline" (uri-encoded), and with the system path instead of the url. It's a localhost windows system if that's relevant.

Prefix -> preprocess.path

I can't get how preprocess.path works.

LESS files are in /client/assets/less/
CSS files should be in /client/public/css/

Here is my current code:

app.use require('less-middleware') "#{__dirname}/client/assets/less",
  dest: "#{__dirname}/client/public/css"
  preprocess:
    path: (pathname, req) ->
      pathname.replace '/css', ''

Please update to 0.1.13

I'd love to add source maps to webmaker.org, please update when you get a chance? Thanks!

Express temp directory example - security issue

var lessMiddleware = require('less-middleware'),
    os = require('os');

var app = express();

app.configure(function () {
    // Other configuration here...

    var tmpDir = os.tmpDir();
    app.use(lessMiddleware({
        src: __dirname + '/public/stylesheets',
        dest: tmpDir,
        compress: true
    }));

    app.use(express.static(__dirname + '/public'));
    app.use(express.static(tmpDir));
});

In above temp directory, example , os.tmpDir() is directly added as static directory. so it exposes everything in os.tmpDir() and anyone can download files from os.tmpDir() as far as they know filename.

solution, create a subdirectory in os.tmpDir()

var tmpDir = path.join(os.tmpDir(), 'css-cache')

Provide HISTORY.md file

Please provide a HISTORY.md file in which you document what changed in each version. I am currently updating a web site I developed over a year ago, and it's unclear how I should otherwise find this information.

Option For Only Compiling Once

Add option for only compiling the css file one time for production use.

Mainly this is to prevent the less file from being checked for updates on every request for the css file.

For we must make a folder for the compiled files?

If it was thought that seems quite absurd to compile the less. And keep them in the file system, instead of being sent directly.

less.parse( data, function (Error, tree) {
    res.contentType('text/css');
    res.send(tree.toCSS());
} );

And no need to keep on the server, the css.

EMFILE Error from less

Hi,

I have some problems uisng your middleware. locally my less files will compile with lessc 1.3.3

My test code also compiles the css:

var fs = require("fs"),
    less = require("less");

var parser = new less.Parser({
    paths: ["/Users/xxx/Developing/etc/less"],
    filename: "/Users/xxx/Developing/etc/less/main.less",
    optimization: 0,
    dumpLineNumbers: 0
});

parser.parse(fs.readFileSync("/Users/xxx/Developing/etc/less/main.less").toString(), function(err, tree) {
   try {
       console.log(tree.toCSS());
   } catch (e) {
       console.log(e);
   }
});

I have copied this from you module code and stripped out the parse function. The result is the working css.

If I compile the exact same less with the middleware I get the following error:

LESS undefined error : EMFILE, open '/Users/xxx/Developing/etc/less/plans.less'
LESS File : undefined undefined:undefined
Error: EMFILE, open '/Users/xxx/Developing/etc/less/plans.less'

Can you help me solving this?

Issue with path offset in request path.

How can I set the offset path.

Example: /global.css
What I want: /css/global.css

I cannot see an option for this, please correct me if I am wrong which I probably am :)

Error Reporting in Debug Mode

Output errors from failed parsing of less files when there is a problem parsing the file. Include any information that is available.

Don't serve .less files

.less files are still served when this middleware is used, which could be a code security/privacy issue.

'TypeError: Arguments to path.join must be strings' in new express project

In a freshly created express project, I am receiving the following error:

TypeError: Arguments to path.join must be strings
    at f (path.js:204:15)
    at Object.filter (native)
    at Object.exports.join (path.js:209:40)
    at Object.handle (F:\development\expresstest\node_modules\less-middleware\lib\middleware.js:128:26)
    at next (F:\development\expresstest\node_modules\express\node_modules\connect\lib\proto.js:193:15)
    at pass (F:\development\expresstest\node_modules\express\lib\router\index.js:110:24)
    at Router._dispatch (F:\development\expresstest\node_modules\express\lib\router\index.js:173:5)
    at Object.router (F:\development\expresstest\node_modules\express\lib\router\index.js:33:10)
    at next (F:\development\expresstest\node_modules\express\node_modules\connect\lib\proto.js:193:15)
    at Object.methodOverride [as handle] (F:\development\expresstest\node_modules\express\node_modules\connect\lib\middleware\methodOverride.js:48:5)

Steps to recreate:

$ express --css less
$ npm install
$ node app.js

Express server listening on port 3000

Error appears after navigating to localhost:3000. I'm using Express v3.4.8 and Node v0.10.26 on Windows.

Thanks!

Conditional execution via guarded mixins supported?

Hi,

I would like to know if Conditional execution via guarded mixins is supported? I'm trying to use it but it throw me an error.
Did you use/test it ?

Error:
node_modules\less-middleware\node_modules\less\lib\less\parser.js:385
throw new(LessError)(e, env);
^

Example from LessCss website:

.mixin (@a) when (lightness(@a) >= 50%) {
background-color: black;
}

thank

J.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.