如何使用grunt递归编译less/sass文件



我有一个文件结构复杂的项目,其中有一些模块有自己的css/less/sass文件夹。

我希望grunt监视所有这些文件,并通过用css替换最后一个lass/sass文件夹将它们编译到目标文件。编译的文件示例

root/less/style.less -> root/css/style.css

root/modules/mymodule/sass/file.sass -> root/modules/mymodule/css/file.css

我现在的咕哝文件是:

    less: {
        development: {
            options: {
                paths: ["**/*"]
            },
            //files: {"css/main.css": "less/main.less"},
            files: [
                {
                    expand: true,
                    cwd: "**/*",
                    src: ["**/*.less"],
                    dest: "",
                    ext: ".css"
                }
            ]
        }
        // ,
        // production: {
        //     options: {
        //         paths: ["assets/css"],
        //         cleancss: true
        //     },
        //     files: {"path/to/result.css": "path/to/source.less"}
        // }
    },
    watch: {
      styles: {
        files: ['less/**/*.less'], // which files to watch
        tasks: ['less'],
        options: {
          nospawn: true
        }
      }
    }
});

但它不起作用。

我认为是启动(cwd)和目标(dest)路径不正确。试试这个:

less: {
    development: {            
        files: [
            {
                expand: true,
                cwd: "root", // The startup directory
                src: ["**/*.less"],
                dest: "root", // Destination
                ext: ".css"
            }
        ]
    }
},

最新更新