diff --git a/lib/middleware.js b/lib/middleware.js index 5cb4ab4..41b85b0 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -209,18 +209,31 @@ module.exports = less.middleware = function(options){ } var cssPath = path.join(dest, pathname); - var lessPath = path.join(src, ( - regex.compress.test(pathname) - ? pathname.replace(regex.compress, '.less') - : pathname.replace('.css', '.less' - ))); - - if (root) { - cssPath = path.join(root, dest, pathname.replace(dest, '')); - lessPath = path.join(root, src, pathname - .replace(dest, '') - .replace('.css', '.less')); - } + + if (typeof(src) == 'string') src = [ src ]; + + var lessPath = null; + src.forEach(function( s ) { + if (lessPath) return; + + var testPath = path.join(s, ( + regex.compress.test(pathname) + ? pathname.replace(regex.compress, '.less') + : pathname.replace('.css', '.less' + ))); + + if (root) { + cssPath = path.join(root, dest, pathname.replace(dest, '')); + testPath = path.join(root, s, pathname + .replace(dest, '') + .replace('.css', '.less')); + } + + var exists = fs.existsSync( testPath ); + + if (exists) lessPath = testPath; + + }); log('source', lessPath); log('dest', cssPath); @@ -233,6 +246,8 @@ module.exports = less.middleware = function(options){ // Compile to cssPath var compile = function() { log('read', lessPath); + + if (!lessPath) return error({ code: 'ENOENT' }); fs.readFile(lessPath, 'utf8', function(err, str){ if (err) { return error(err); }