【问题标题】:GruntJS: Cannot call method filter of undefinedGruntJS:无法调用未定义的方法过滤器
【发布时间】:2014-10-07 13:00:41
【问题描述】:

我是 grunt 的新手,并尝试将其安装在一个简单的项目中。它有效,但是当我尝试运行“ugilfy”我的文件时,我不断收到此错误:

cannot call method   'filter' of undefined'

这是我的 grunt 文件 (Gruntfile.js),保存在我项目的根目录中:

module.exports = function(grunt)


{

grunt.initConfig({

    uglify: 
    { 
        options: 
        {
            mangle: true, 
            compress:true, 
            sourceMap: "dist/app.map", 
            banner: "/*  2014 */" 
        },

        //set of files where the plugin works on, (files which we can affect with our plugins like uglify)
        // culd be dev or production 
        target: 
        {

            //folder name equal to the JS object!!!
            js: "js/app.js", 
            dest: "dist/app.min.js"
        }
    }

});



//load plug-ins
grunt.loadNpmTasks('grunt-contrib-uglify'); 


};

我真的不知道为什么它不起作用。我尝试在谷歌上搜索,但找不到任何答案。

【问题讨论】:

  • 听起来它不喜欢你的一些 Javascript。 grunt --force 为你做了什么吗?
  • 不,仍然无法正常工作:(我收到相同的警告,但未创建文件:/
  • 嗯,这是一个很长的镜头。您需要检查您的 Javascript。 jslint.com 之类的工具会有所帮助。

标签: javascript gruntjs grunt-contrib-uglify


【解决方案1】:

uglify.target 缺少 src 属性。

改变

js: "js/app.js",

src: "js/app.js",

它应该可以正常工作。

更多关于指定来源和目的地的信息是in the Grunt docs

【讨论】:

  • 嘿,工作! :) 它总是必须被称为'src'吗?我认为这取决于您的文件夹名称。非常感谢!
  • 很高兴它对你有用!请参阅docs on file mappings 了解您可以指定这些的不同方式(因为有多种方式),但一般来说,如果您有dest,则需要src
猜你喜欢
  • 2011-06-20
  • 2019-11-27
  • 1970-01-01
  • 2013-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多