gpt4 book ai didi

angularjs - grunt-contrib-requirejs 中的垫片未包装库

转载 作者:行者123 更新时间:2023-12-02 23:37:41 24 4
gpt4 key购买 nike

我正在使用 requirejs 并配置我的产品工件,从而组合我的库并在它们之间设置模块依赖关系,以便使用 requirejs 的 grunt 任务获得适当的加载顺序。在我的 livereload 服务器中使用运行时模块注入(inject)没有问题,该服务器可以访问非组合库。为了清楚起见,我禁用了所有缩小/丑化并打开了 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 定义函数中,但是我没有发现这种情况发生。

    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 (或我的管道中的 Assets 修改器之一)自动为我包装模块。任何人都可以给我一个提示,我认为 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”,垫片配置应该已经在优化器中,这通常是另一个失败点。

关于angularjs - grunt-contrib-requirejs 中的垫片未包装库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19521423/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com