requirejs: { dist: { // Options: https://github.com/jrburke/r.js/blob/master/build/example.build.js options: { // `name` and `out` is set by grunt-usemin // name: 'App',baseUrl: yeomanConfig.app + '/scripts',mainConfigFile: yeomanConfig.app + '/scripts/config.js',out: yeomanConfig.dist + '/scripts/main.js',optimize: 'none',// TODO: Figure out how to make sourcemaps work with grunt-usemin // https://github.com/yeoman/grunt-usemin/issues/30 //generateSourceMaps: true,// required to support SourceMaps // http://requirejs.org/docs/errors.html#sourcemapcomments beautify: false,removeCombined: false,generateSourceMaps: false,preserveLicenseComments: false,useStrict: true,mangle: false,compress: false,// wrap: true,// https://github.com/mishoo/UglifyJS2 } } },
我正在使用Kendo,Angular和Angular-Keno-UI.我知道Kendo是AMD模块就绪,但它看起来不像Angular-Keno-UI.我期望创建一个垫片并将其包装在相应的requirejs define函数中,但是我发现这不会发生.
require.config({ cjsTranslate: true,paths: { jquery: 'vendor/jquery/jquery','angular-kendo-ui': 'vendor/angular-kendo-ui/build/angular-kendo',kendo: 'vendor/kendoui.complete.2013.2.918.trial/js/kendo.all.min',angular: 'vendor/angular/angular',requirejs: 'vendor/requirejs/require','angular-animate': 'vendor/angular-animate/angular-animate','angular-ui-router': 'vendor/angular-ui-router/release/angular-ui-router.min','angular-resource': 'vendor/angular-resource/angular-resource' },shim: { jquery: { exports: '$' },angular: { deps: [ 'jquery' ],exports: 'angular' },'angular-resource': { deps: [ 'angular' ] },'angular-kendo-ui': { deps: [ 'angular','kendo' ] },'angular-ui-router': { deps: [ 'angular' ] } } });
为了解决模块准备不足的问题,我自己包装:
define('angular-kendo-ui',[ 'angular','kendo' ],function ( angular,kendo ) { < original angular-kendo-ui source > });
我误解了垫片的应用吗?它似乎我有它并没有实际包装定义的路径,而只是指向它如果请求模块(这在动态模块加载中很好)
在我最初审查这些技术的过程中,我注意到有一种方法可以让requirejs(或我管道中的一个资产变换器)自动为我包装模块.任何人都有我的提示,我认为这是requirejs将配置中定义的模块包装为路径,但也许我错了.下面是正在运行的任务的打印输出:
Done,without errors. Elapsed time build 887ms useminPrepare:html 22ms concurrent:dist 8s autoprefixer:dist 174ms requirejs:dist 19s jsbeautifier:dist 2s concat:public/styles/main.css 46ms concat:public/scripts/main.js 56ms cssmin:public/styles/main.css 81ms copy:dist 26ms usemin:html 5s usemin:css 24s
解决方法
As of 2.1.11,shimmed dependencies can be wrapped in a define() wrapper
to help when intermediate dependencies are AMD have dependencies of their
own. The canonical example is a project using Backbone,which depends on
jQuery and Underscore. Shimmed dependencies that want Backbone available
immediately will not see it in a build,since AMD compatible versions of
Backbone will not execute the define() function until dependencies are
ready. By wrapping those shimmed dependencies,this can be avoided,but
it could introduce other errors if those shimmed dependencies use the
global scope in weird ways,so it is not the default behavior to wrap.
所以也许使用:
wrapShim: true
https://github.com/jrburke/r.js/blob/master/build/example.build.js
因为你使用“mainConfigFile”,shim配置应该已经在优化器中,这通常是另一个失败点.