seajs2.0加载js的一个疑问

56 views
Skip to first unread message

jut leo

unread,
Apr 11, 2013, 2:28:23 AM4/11/13
to se...@googlegroups.com
我在加载jquery-1.9.1.js时是这么配置的:
         alias: {
   'jquery': {
     src: 'jquery-1.9.1.js',
     exports: 'jQuery'
   }
         }

在我的js里这么使用 var jQuery = $ = require('jquery');

一切都运行OK, 但是有个不解的疑问

在firebug里看到seajs.cache里有如下两个
/libs/jquery-1.9.1.js
/libs/jquery.js

不知道这是为什么?







Frank Wang

unread,
Apr 11, 2013, 2:30:17 AM4/11/13
to seajs
这个是对的

一个是指向真实的 jquery-1.9.1.js
另一个是动态封装成 CMD 格式的虚拟 jquery.js









--
You received this message because you are subscribed to the Google Groups "seajs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seajs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
王保平 / 玉伯(射雕)
送人玫瑰手有余香

jut leo

unread,
Apr 11, 2013, 2:44:37 AM4/11/13
to se...@googlegroups.com
这个会引起误导,以为这是哪里配置错了,加载了两个一个是错误的。 另外我采用同样的加载方式加载mustache,
                   'mustache': {
    src: 'mustache/mustache.js',
    exports: 'mustache'
   }
 libs/mustache.js
libs/mustache/mustache.js


var jMustache = require('mustache');

jMustache  对象是一个Object{ }

我尝试分别使用了 sea gallery 提供的mustache.js和原版的mustache.js,包括debug版本 返回都是一个空对象,目前我还在测试中。不知道有没有遇到过此类问题?


在 2013年4月11日星期四UTC+8下午2时30分17秒,Frank Wang写道:

Frank Wang

unread,
Apr 11, 2013, 3:03:46 AM4/11/13
to seajs
非 CMD 版本,才配 shim 的 alias 配置

普通的,直接:

seajs.config({
  alias: {
      mustache: 'path/to/mustache.js'
  }
})


2013/4/11 jut leo <jut...@gmail.com>

jut leo

unread,
Apr 11, 2013, 3:04:49 AM4/11/13
to se...@googlegroups.com
配置alias ,
   'mustache': {
    src: 'mustache/mustache.js',
    exports: 'mustache'
   }

经过测试: sea gallery 提供的mustache.js和原版的mustache.js均无法使用mustache, 如果不配置alias,通过require('mustache/mustache');可正常使用


在 2013年4月11日星期四UTC+8下午2时44分37秒,jut leo写道:

Frank Wang

unread,
Apr 11, 2013, 3:14:44 AM4/11/13
to seajs
如果用的是这个 mustache.js:


配置:

alias: {

  "mustache": "gallery/mustache/0.7.2/mustache"
}

这样才对。

如果是用的官方的 mustache.js,需要激活 shim 插件,并配置:

alias: {

  mustache: {
       'src': 'path/to/mustache.js',
       exports: "Mustache"
  }
}


2013/4/11 jut leo <jut...@gmail.com>

jut leo

unread,
Apr 11, 2013, 3:28:59 AM4/11/13
to se...@googlegroups.com
找到问题了:
exports: "mustache" 我将这个‘m’写成小写了,返回的对象就是new Object {};  exports: "Mustache"这样就正常了。

查看mustache源码 有这样一段 // All Mustache.* functions use this writer.

感谢你的耐心回复

在 2013年4月11日星期四UTC+8下午3时14分44秒,Frank Wang写道:
Reply all
Reply to author
Forward
0 new messages