Sometimes it's useful to get a list of all @imports for a given .less file, especially if you want to watch those files for changes in your gulp or grunt build steps. We can easily achieve this using the LESS parser itself!

Disclaimer... this relies on internal implementation details of the LESS.js library and as such could break at any time. That being said, this code should work on all LESS.js versions stretching right back to v1.3!

Sample use


I've rolled the above code into a gulp plugin called gulp-watch-less, which works exactly like the gulp-watch plugin but also tracks changes to all @import paths of the files. Neat!

Take a look at the official repo for more information on how to use this in your work flow