如何引用捆绑的js文件(asp.net mvc4)在Require.js? [英] How to reference the bundled js files (asp.net mvc4) in Require.js?

查看:158
本文介绍了如何引用捆绑的js文件(asp.net mvc4)在Require.js?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在学习SPA约翰爸爸的pluralsight课程。

I have been studying John Papa's pluralsight course on SPA.

在他的 main.js ,他出了名的每个js的包含在捆绑库。

In his main.js, he gave a name to each js library which is included in the bundle.

(function () {
var root = this;

define3rdPartyModules();


function define3rdPartyModules() {
    // These are already loaded via bundles. 
    // We define them and put them in the root object.
    define('jquery', [], function () { return root.jQuery; });
    define('ko', [], function () { return root.ko; });
    define('amplify', [], function () { return root.amplify; });
    define('infuser', [], function () { return root.infuser; });
    define('moment', [], function () { return root.moment; });
    define('sammy', [], function () { return root.Sammy; });
    define('toastr', [], function () { return root.toastr; });
    define('underscore', [], function () { return root._; });
}

})();

但什么是在这里?

通过这样做,我们可以调用在定义语句的短名称:

By doing so, we can call those short names in the define statement:

define('vm.session',
['ko', 'datacontext', 'config', 'router', 'messenger', 'sort'],
function (ko, datacontext, config, router, messenger, sort) {

目前,我不知道该怎么做。所以,我的工作定义语句是丑陋的:

define('vm.admin.outfitters',
['/Scripts/lib/jquery-1.8.1.js', '/Scripts/lib/jsrender.js', ...], function(){...

我知道,有一定有一个更好的办法。所有这些js文件已经包含在脚本包了。我怎么可以参考这些脚本?

I know there's gotta be a better way. All those js files have been included in the script bundle already. How can I reference those scripts?

推荐答案

RE:根

RequireJS和AMD准备库中删除从全球范围内的对象(之类的东西正)。有些插件希望他们在全球范围内,所以我们可以垫片这些插件或弹出的对象回来全局范围。后者是在这个code发生。它正在做的插件淘汰赛为主。

RequireJS and the AMD ready libraries remove the objects from the global scope (things like ko). Some plugins want them in global scope, so we can either shim those plugins or pop the objects back in global scope. The latter is what is happening in this code. It's being done for the plugins for Knockout primarily.

RE:你定义报表

第一个参数是的模块的名称,让你的罚款那里。第二个参数是模块RequireJS意识到的列表。第三个参数是匹配的变量重新present它。因此,在您code你可能有这样的事情...

The first parameter is the name of of the module, so you are fine there. THe second parameter is the list of modules that RequireJS is aware of. The 3rd parameter is the matching variable to represent it. So in your code you might have something like this ...

define('vm.admin.outfitters',
['jquery', 'jsrender'], function($, jsrender) { 

这篇关于如何引用捆绑的js文件(asp.net mvc4)在Require.js?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆