本文介绍了$喷油器:modulerr后r.js优化,而不是之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 require.js r.js 优化。 pre-优化,我有:

  // MainCtrl.js
定义(函数(){
    返回[$范围功能($范围){执行console.log($范围内); }];
});// main.js
require.config({
    垫片:{
        角度:{
            出口:角,
        },
    },
    路径:{
        角:LIB / angular.min
    },
});
需要([角,MainCtrl],功能(NG,MainCtrl){
    的console.log(纳克);
    VAR应用= ng.module(MyApp的,[]);
    app.controller(MainCtrl,MainCtrl);
});

我的HTML是非常简单的;它只是 NG-应用=的myapp 在< HTML> NG-控制器= MainCtrl <车身方式>

当我运行这样的应用程序,一切似乎工作。我得到的的console.log 纳克这似乎是对象。然后,我得到的的console.log $范围 MainCtrl 。没有问题。

运行后 r.js ,并使用缩小的 main.js ,我得到的错误和东西不再起作用。我跑 r.js -o build.js

  // build.js
({
    APPDIR:公,
    的baseUrl:JS
    导演:DIST
    fileExlusionRegExp:/^(r|build\\.js)$/,
    优化:uglify2
    optimizeCss:标准,
    模块:[{
        名称:主
    }],
    路径:{
        角:LIB / angular.min
    },
})

现在的,当我访问 index.html的我得到的错误:

  1. Seems to indicate that angular is not loading properly or something. It can't inject something to myapp, but it has no dependencies. Not ngRoute or anything
  2. ng is now undefined even though it was correctly angular before. This also causes the second error
  3. The console.log in MainCtrl is not called. Not a huge surprise since there is an error on the previous line. However, if I change ng to angular the undefined error does not occur and app.controller gets called, but the console.log from MainCtrl is still not called.

My only guess is that angular is being minified twice (I'm already using angular.min.js and then r.js minifies it again). Can I do anything to fix this issue?

解决方案

In the shim documentation, it is suggests:

This is probably causing angular's shim to be absent from the built file.

这篇关于$喷油器:modulerr后r.js优化,而不是之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 06:59