加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 来自grunt-contrib-requirejs的Shim不包装库

发布时间:2020-12-17 06:46:42 所属栏目:安全 来源:网络整理
导读:我使用requirejs并配置我的产品工件,因此组合我的库并在它们之间设置模块依赖关系以使用requirejs的grunt任务获得适当的加载序列.在我的livereload服务器中使用运行时模块注入没有问题,它可以访问非组合库.为了清楚起见,我禁用了所有缩小/丑化并开启了js-bea
我使用requirejs并配置我的产品工件,因此组合我的库并在它们之间设置模块依赖关系以使用requirejs的grunt任务获得适当的加载序列.在我的livereload服务器中使用运行时模块注入没有问题,它可以访问非组合库.为了清楚起见,我禁用了所有缩小/丑化并开启了js-beautify.

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配置应该已经在优化器中,这通常是另一个失败点.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读