2

I am using less-middleware for my node JS express app however I am having a problem in that if I update my screen.less file, it does not recompile again. To get the file to recompile I have to delete the generated .css file and reload the site.

Any ideas why this would be happening?

LESS Complier

    app.use(express.static(path.join(__dirname, 'public'))); // set static resource directory
    app.use(require('less-middleware')({
        // LESS CSS compiler
        src : path.join(__dirname, 'public'),
        yuicompress : true
    }));

Directory structure:

public
    stylesheets
        _functions.less
        _normalize.less
        _params.less
        screen.less
app.js
package.json

Any help would be appreciated! Many thanks.

3
  • @JoachimIsaksson thanks for the response but that is related to less js not node.js less compiler. Commented Oct 21, 2013 at 9:21
  • src : path.join(__dirname, 'public'), should be src : path.join(__dirname, 'public','stylesheets'),, no? Commented Oct 21, 2013 at 10:37
  • @krasu That doesn't seem to be the way it works. The code is very similar to the solution documented on less-middleware docs - github.com/emberfeather/less.js-middleware#express Also the CSS does seem to be compiling no problem, the issue is recompiling is just not happening. Commented Oct 21, 2013 at 10:48

1 Answer 1

3

Have found out the issue and it was referenced by less-middleware.

Basically, you have to declare less middleware before you declare the static resource location. So my new, working code is now as below

    app.use(require('less-middleware')({
        // LESS CSS compiler
        src : path.join(__dirname, 'public'),
        yuicompress : true
    }));
    app.use(express.static(path.join(__dirname, 'public'))); // set static resource directory
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.