简体   繁体   English

笨拙地创建和运行较少的编译任务

[英]grunt create and run less compile task

i am very new to grunt and i wanted to achieve following goal 我对咕gr非常陌生,我想实现以下目标

  • iterate every directory in pointed location 在指定位置迭代每个目录
  • compile less file to css 编译更少的文件到CSS

source: 资源:

  • theme 1 主题1
    • file.less 无档案
  • theme 2 主题2
    • file.less 无档案
  • theme 3 主题3
    • file.less 无档案

after processing: 处理后:

  • theme 1 主题1
    • file.less 无档案
    • out.css out.css
  • theme 2 主题2
    • file.less 无档案
    • out.css out.css
  • theme 3 主题3
    • file.less 无档案
    • out.css out.css

I read somewhere that grunt does that, this is my entire run.js file: 我在某处读到那个咕gr的声音,这是我的整个run.js文件:

var grunt = require('grunt'),
    less = require('less');

  grunt.initConfig({
    less: {
      compileCore: {
        options: {
          strictMath: true
        },
        files: [{
          expand: true,
          src: ['themes/**/file.less'], 
          ext: '.css',
          extDot: 'first'
        }]
      }
  }
  });

  grunt.registerTask('default', ['less']);

  grunt.task.run('default');

it doesnt give any errors but it doesnt work either, how can i make this to work? 它没有给出任何错误,但也不起作用,如何使它起作用? (again, i have no exprience with grunt whatsoever, yet) (再次,我对咕have声没有任何了解)

if its possible also to achieve this goal with just command line execution (without runing node.js file) that would be good too ;) 如果仅通过命令行执行(不运行node.js文件)也有可能达到这个目标,那也将是一件好事;)

you can use grunt.file.expandMapping ( https://gruntjs.com/api/grunt.file#grunt.file.expandmapping ) to iterate through all the files in a directory and provide options to according to the requirements. 您可以使用grunt.file.expandMapping( https://gruntjs.com/api/grunt.file#grunt.file.expandmapping )遍历目录中的所有文件,并根据需要提供选项。

The below code will work according to your requirement. 以下代码将根据您的要求工作。

 module.exports = function (grunt) { grunt.initConfig({ less: { development: { files: grunt.file.expandMapping(['themes/**/*.less'], '', { rename: function (destBase, destPath) { return destBase + destPath.replace('.less', '.css'); } }) } } }); grunt.loadNpmTasks('grunt-contrib-less'); grunt.registerTask('default', ['less']); } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM