我正在尝试将requirejs集成到现有项目中,该项目在node / grunt堆栈上运行.我想使用r.js优化器将所有内容连接在一起并通过依赖关系来实现它的魔力.
我能够让r.js构建一个.js文件,并且没有错误……但没有任何反应.我在我的代码中设置了断点,但没有任何东西被启动 – 应用程序从未实际运行bootstrap.js文件.我已经尝试将bootstrap.js放在一个立即函数中,当然它确实运行了,但依赖项尚未加载(似乎).我在这里错过了什么?
文件结构:
app -> modules - -> common - - -> auth.js // contains an auth call that needs to return before I bootstrap angular -> app.js -> index.html config -> main.js node_modules vendor -> angular/jquery/require/domready/etc gruntfile.js
gruntfile requirejs任务:
requirejs: { compile: { options: { name: 'app',out: 'build/js/app.js',baseUrl: 'app',mainConfigFile: 'config/main.js',optimize: "none" } } },
main.js配置:
require.config({ paths: { 'bootstrap': '../app/bootstrap','domReady': '../vendor/requirejs-domready/domReady','angular': '../vendor/angular/angular','jquery': '../vendor/jquery/jquery.min','app': 'app','auth': '../app/modules/common/auth',requireLib: '../vendor/requirejs/require' },include: ['domReady','requireLib'],shim: { 'angular': { exports: 'angular' } },// kick start application deps: ['bootstrap'] });
app.js:
define([ 'angular','jquery',],function (angular,$) { 'use strict'; $( "#container" ).css("visibility","visible"); return angular.module('app'); });
bootstrap.js:
define([ 'require','angular','app','auth' ],function (require,angular,app,$,auth) { var Authentication = auth.getInstance(); .. do auth stuff... if (Authentication.isAuthorized) { require(['domReady!'],function (document) { angular.bootstrap(document,['app']); }); } );