【问题标题】:Grunt.js concatenates and breaks angular.js project?Grunt.js 连接和中断 angular.js 项目?
【发布时间】:2014-06-23 16:37:18
【问题描述】:

我有一个 Angular.js 项目。我可以使用 grunt serve 并且它运行良好。但是,当我将它构建到 dist 文件夹时,它不会运行并且控制台会抛出错误:

Uncaught Error: [$injector:modulerr] Failed to instantiate module designSystemApp due to:
Error: [$injector:unpr] Unknown provider: a
http://errors.angularjs.org/1.2.6/$injector/unpr?p0=a
at http://0.0.0.0:9000/scripts/vendor.js:3:30474
at ...<omitted>...2) 

构建没有错误,文件(Bower 组件)被连接到 vendor.js。但是浏览器出错了。该错误是针对最小化文件的,因此调试该错误有点困难。有人见过这个吗?

我的 grunt 文件在这里:https://gist.github.com/smlombardi/7fa15161b60c2f63f416

我有点失落。谢谢。

【问题讨论】:

    标签: javascript node.js angularjs gruntjs


    【解决方案1】:

    您可以通过多种方式处理您的依赖注入。例如:

    function injectableFunc($someService, someOtherDependency) {...}
    

    ['$someService', 'someOtherDependency', 
        function (thisWillBeSomeService, nameDoesNotMatter) {...}]
    

    主要区别在于第二种形式“存活”了缩小,因为依赖关系由数组的第一个字符串项标识(并且字符串不会被缩小)。
    第二种形式在缩小后会中断,因为变量名(用于识别注射剂)发生了变化。

    如果您的工作流程包括缩小(它应该),您可以:

    1. 使用第二种形式
    2. 使用ngmin进行缩小,可以在不破坏应用的情况下处理第一种形式。

    【讨论】:

    • 谢谢,我使用的是 ngmin,但我相信它指向了错误的文件。那解决了它。另一位开发人员告诉我,他按照您的说法“修复​​”了注射,但我猜不是。我会使用 ngmin 来确定。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    • 1970-01-01
    • 2011-01-27
    相关资源
    最近更新 更多