Chris
Chris

Reputation: 2035

Node JS less-middleware not auto compiling

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.

Upvotes: 2

Views: 2425

Answers (1)

Chris
Chris

Reputation: 2035

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

Upvotes: 3

Related Questions