3

I am at a loss as to why the less task fails silently. If I run it using grunt-cli and Gruntfile.js it works fine, but when I try to port it into another script the less task does not generate any output. Any help or insight as to why would be greatly appreciated.

'use strict';

var grunt = require('grunt'),
    _ = require('underscore'),
    path = require('path'),
    fs = require('fs'),
    dir = require('node-dir');

var cssSrc = [];
var cssPaths = [];
var templates = [];
dir.paths('repo', function (err, paths) {
    if (err) {
        throw err;
    }

    _.each(paths.files, function (file) {
        if (path.extname(file) === '.less') {
            cssSrc.push(file);
        }
    });
    cssPaths = paths.dirs;

    grunt.task.loadNpmTasks('grunt-contrib-less');
    grunt.initConfig({
        less: {
            options: {
                paths: cssPaths
            },
            files: {
                'tmp/target.css': cssSrc
            }
        }
    });

    grunt.task.run('less');
});
4

1 回答 1

0

隐含的依赖项grunt-cli

  • 没有选择
  • 查找同步
  • 解决

未明确包含在独立脚本中。

Gruntfile.js脚本包含路径信息:

  • repodir.paths使用回调找到的路径
  • tmp/target.css使用找到的路径_.each
  • .less 使用找到的源路径paths.dirs

并使用依赖项进行寻路。

关于通过Rhinowsh运行 less 有一些不相关的问题,这些问题明确地解释了进行路径查找的参数。

参考

于 2014-11-05T16:54:17.443 回答