【问题标题】:Copy is not working in grunt复制在咕噜声中不起作用
【发布时间】:2016-01-02 09:16:07
【问题描述】:
module.exports = function(grunt) {
grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
copy: {
              files: [
                {expand: true,cwd:"js/" ,src: ['libs/*'], dest: '../test/js/libs/'},
                {expand: true,cwd:"js/" , src: ['models/*'], dest: '../test/js/models/'}

              ]
        }
});
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.registerTask("testcopy",["copy"] );
);

我正在学习 grunt 并且在复制时遇到以下问题。 Warning: undefined is not a function Use --force to continue. 并且文件未从 src 复制到目标

【问题讨论】:

  • 上述代码的哪一行发生了错误?
  • 它没有提供任何行号。只是一条消息警告:未定义不是函数使用--force继续。
  • 有一个); 而不是}; 这是您的代码错误还是堆栈溢出?

标签: javascript gruntjs grunt-contrib-copy


【解决方案1】:

这不是您问题的解决方案。但是对于复制或删除之类的事情,我总是直接使用 cli 命令:https://github.com/sindresorhus/grunt-shell

【讨论】:

    【解决方案2】:

    grunt-contrib-copy 是一个多目标任务,这意味着您必须为其每个配置指定一个“名称”(称为目标) - 这样您就可以定义和调用多个复制操作(请参阅http://gruntjs.com/configuring-tasks#task-configuration-and-targets) .

    您可以通过在“副本”及其参数之间插入名称来做到这一点。下面是我将目标称为“main”的示例:

    module.exports = function(grunt) {
      grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        copy: {
          main: {
            files: [
              {expand: true,cwd:"js/" ,src: ['libs/*'], dest: '../test/js/libs/'},
              {expand: true,cwd:"js/" , src: ['models/*'], dest: '../test/js/models/'}
            ]
          }
        }
      });
      grunt.loadNpmTasks('grunt-contrib-copy');
      grunt.registerTask("testcopy",["copy:main"] );
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-30
      • 2015-01-05
      • 2013-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多