【问题标题】:How to compile all scripts in their own directories with Grunt Coffee?如何使用 Grunt Coffee 编译它们自己目录中的所有脚本?
【发布时间】:2014-09-16 13:19:35
【问题描述】:

这是我目前拥有的:

    coffee: {
        options: {
            bare: true
        },          
        glob_to_multiple: {
            expand: true,
            flatten: false,
            cwd: 'public/js',
            src: ['*.coffee'],
            dest: 'public/js',
            ext: '.js'
        }
    },

问题是我有两个包含我的 JS 文件的目录,我不知道如何设置它来监视这两个地方,并将 javascript 编译到咖啡脚本所在的相同目录中。

这是我试图复制以下功能的咖啡脚本命令:coffee --watch --compile。

【问题讨论】:

    标签: coffeescript gruntjs grunt-contrib-coffee


    【解决方案1】:

    如果我理解正确,你想将coffee从两个目录编译成JS,有两个简单的解决方案供你使用。

    第一种解决方案-将JS文件编译到与原始CoffeeScript文件相同的目录:

      coffee:
         options:
            bare: true
         compile:
            files: [
               expand: true
               src: ['js/**/*.coffee', 'other/**/*.coffee']
               dest: './'
               ext: '.js'
            ]
    

    第二种解决方案 - 将 JS 文件编译到所有咖啡文件的公共目录..(但它保留了相对路径,所以如果你有 coffee/hello.coffe,它将被放入 js/coffee/hello.js

      coffee:
         options:
            bare: true
         compile:
            files: [
               expand: true
               src: ['js/**/*.coffee', 'other/**/*.coffee']
               dest: 'js/'
               ext: '.js'
            ]
    

    希望对您有所帮助,否则您可以为每个目录尝试不同的设置,如下所示:

      coffee:
         options:
            bare: true
         compileOneDir:
            #...
         compileSecondDir:
            #...
    

    【讨论】:

      猜你喜欢
      • 2013-02-11
      • 2012-02-07
      • 2013-07-22
      • 2014-02-25
      • 2010-10-12
      • 1970-01-01
      • 2014-11-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多