prevent grunt-contrib-less imports from compiling

496 Views Asked by At

Is there a way to prevent grunt-contrib-less from compiling files that have an underscore?

I have a set of files which are being imported in the main file. The imported files have a been prefixed with an underscore @import "_fileone" but because im using grunt with dynamic mapping, all .less files are being compiled - whereas im only interested in the main file.

3

There are 3 best solutions below

0
On

You can create a second grunt task that process this underscore files with the option of no compress, mangler etc.

You could also separate this underscore and normal in two tasks, and have watch to look at both eventually

1
On

Not sure if this answers your question, but as of less.js 1.5 if you use the @import reference directive, those files will not compile but their references (mixins etc) will be available for use in the less file.

From the less.js docs:

**Import Options**
Less offers several extensions to the CSS @import CSS at-rule to provide more flexibility over what you can do with external files.
Syntax: @import (keyword) "filename";

The following import directives have been implemented:

reference: use a Less file but do not output it
inline: include the source file in the output but do not process it
less: treat the file as a Less file, no matter what the file extension
css: treat the file as a CSS file, no matter what the file extension
once: only include the file once (this is default behavior)
multiple: include the file multiple times
0
On

in your less task ignore files starting with _

src: ['styles/*.less', '!styles/_*.less'],

this is normal grunt way of ignoring, nothing to do with LESS :)