【发布时间】:2014-04-30 16:29:53
【问题描述】:
我正在使用load-grunt-config 和grunt-contrib-copy,我正在尝试让复制任务用“进程”选项替换一些模板标签。
我知道可以替换模板标签(来自 grunt-contrib-copy 文档),但我无法让它工作。我要做的是将“style.css”中的字符串<%= init.project.name %>替换为同名的模板变量(由用户使用grunt-prompt输入)。
在复制时,我希望 grunt 用它在内存中的值替换 style.css 文件中的模板变量。但是当我使用下面的代码时它不会这样做。有谁知道我做错了什么?
Grunt 复制任务
// -------------------------------------
// Grunt copy
// -------------------------------------
module.exports = {
// ----- Copy files for initialization (selected with grunt prompt) ----- //
init: {
files: [{
cwd: 'init/php/templates',
src: '<%= init.php.templates %>',
dest: 'src/php/templates',
expand: true
}, {
cwd: 'init/php/includes',
src: '<%= init.php.includes %>',
dest: 'src/php/includes',
expand: true
}, {
cwd: 'init/js',
src: '<%= init.scripts %>',
dest: 'src/js',
expand: true
}, {
cwd: 'init/css',
src: 'style.css',
dest: 'src/css',
expand: true,
options: {
process: function (content, srcpath) {
return grunt.template.process(content);
}
}
}]
}
};
Css 文件(wordpress)
/*
Theme Name: <%= init.project.name %>
Theme URI:
Description: Description
Version: 1.0
Author: Name
Author URI: uri
Tags: Tags
*/
我试过this 答案,但processContent 已被process 取代,而且这个答案似乎不再起作用(即使将processContent 更改为process)。
【问题讨论】:
标签: javascript node.js gruntjs lodash