【问题标题】:Using templates as a grunt file list使用模板作为 grunt 文件列表
【发布时间】:2013-04-21 00:27:13
【问题描述】:

我正在尝试使用模板通过 Grunt 复制一些文件。目前,我有:

/*global module:false*/
module.exports = function(grunt) {

  var fs = require('fs');
  var path = require('path');
  // Project configuration.
  grunt.initConfig({
    // Metadata.
    pkg: grunt.file.readJSON('package.json'),

    libSrc: ['foo/**'],

    // Task configuration.
    copy: {
        libs: {
                src: ["<%= libSrc %=>"],
                dest: 'src/'
        }

    }
  });

  // These plugins provide necessary tasks.
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-less');
  grunt.loadNpmTasks('grunt-contrib-copy');
  grunt.loadNpmTasks('grunt-dojo');
  grunt.loadNpmTasks('grunt-bless');


  // Default task.
  grunt.registerTask('default', ['jshint']); 

};

我的目录结构是:

.
./.Gruntfile.js.swp
./src
./src/foo
./src/foo/oops.js
./node_modules
./package.json
./foo
./foo/oops.js
./Gruntfile.js

当我运行 Grunt 时,我得到:

grunt copy
Running "copy:libs" (copy) task


Done, without errors.

即没有任何内容被复制。

我尝试用 actual 数组替换模板,一切正常。问题是,我将在此 Gruntfile 的后续迭代中使用其他任务修改 libSrc 的值,因此我确实需要使用模板。

基本的 grunt 文档表明这是一种受支持的方法,尤其是 http://gruntjs.com/configuring-tasks#templates 的示例。

那么,我在这里遗漏了什么吗?为什么模板没有扩展到['foo/**']?有什么建议吗?

【问题讨论】:

    标签: gruntjs


    【解决方案1】:

    简单的错字!

    行:

     src: ["<%= libSrc %=>"],
    

    应该读过

     src: ["<%= libSrc %>"],
    

    【讨论】:

      猜你喜欢
      • 2019-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-18
      • 2014-12-13
      • 2021-07-23
      • 1970-01-01
      • 2014-08-24
      相关资源
      最近更新 更多