如何使用grunt替换副本上的模板变量?

0 javascript node.js gruntjs lodash

我正在使用load-grunt-configgrunt-contrib-copy,我正在尝试使用'process'选项来替换一些模板标签.

我知道替换模板标签是可能的(来自grunt-contrib-copy文档),但我无法让它工作.我要做的是将<%= init.project.name %>"style.css"中的字符串替换为同名的模板变量(由用户使用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);
        }
      }
    }]
  }
};
Run Code Online (Sandbox Code Playgroud)

Css文件(wordpress)

/*
Theme Name: <%= init.project.name %>
Theme URI: 
Description: Description
Version: 1.0
Author: Name
Author URI: uri
Tags: Tags
*/
Run Code Online (Sandbox Code Playgroud)

我已经尝试过这个答案,但processContent已被替换process,而且这个答案似乎不再起作用(即使processContent改为process).

emn*_*178 5

你把选项放在错误的地方,把它移出来它应该工作.

module.exports = function (grunt) {
  return {
      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);
          }
        }
      }
  }
};
Run Code Online (Sandbox Code Playgroud)

更新以适应 load-grunt-config