我正在尝试使用模板通过 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.
即没有任何东西被复制。
我试过用实际的数组替换模板,一切正常。问题是,我将在libSrc
这个 Gruntfile 的后续迭代中修改其他任务的值,所以我确实需要使用模板。
基本的 grunt 文档表明这是一种受支持的方法,特别是http://gruntjs.com/configuring-tasks#templates上的示例。
那么,我在这里错过了什么吗?为什么模板没有扩展为['foo/**']
? 有什么建议么?