关于 2.0.x beta的alias和shim的疑问

52 views
Skip to first unread message

Km Van

unread,
Mar 8, 2013, 11:34:47 PM3/8/13
to se...@googlegroups.com
很高兴能看到2.0版本有各种令人赏心悦目的变化,不过我有些还没解开的疑问。
先上一段代码:
seajs.config({
  alias:{
    'jquery': 'lib/jquery-1.9.1.min.js',
    'jquery.easing': 'lib/jquery.easing.1.3.js'
  },
  // Enable plugins
  plugins: ['shim'],

  // Configure shim for non-CMD modules
  shim: {
    'jquery': {
      src: 'lib/jquery-1.9.1.min.js',
      exports: 'jQuery'
    },
    'jquery.easing': {
      src: 'lib/jquery.easing.1.3.js',
      deps: ['jquery']
    }
  }
});

这段代码,有略显多余的地方吗?是不是每个jq插件,都要按照jquery.easing那样写在shim里面呢?
感谢:)

Chris Chen

unread,
Mar 9, 2013, 9:25:15 PM3/9/13
to se...@googlegroups.com

non-CMD模块采用shim插件,一般的jquery插件,手动转换为CMD插件很容易。只有类似jq ui或者my97那种有内部依赖机制的,建议使用shim。

--
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.
 
 

Km Van

unread,
Mar 9, 2013, 11:13:36 PM3/9/13
to se...@googlegroups.com
那想问一下,如果插件是non-CMD模块的,在alias中写了插件的别名后,在shim里也要再写一次吗?

Chris Chen

unread,
Mar 9, 2013, 11:19:01 PM3/9/13
to se...@googlegroups.com

use non-CMD模块,只能加载代码文件,并执行,不会通过exports提供接口。对于non-CMD模块,要么封装,要么使用shim加载,不建议直接当做标准模块使用。

Km Van

unread,
Mar 10, 2013, 1:12:17 AM3/10/13
to se...@googlegroups.com
感谢您的回复!有点明白了。不过我想参考一下您的意见,之前我是用1.x版本,那时候的jq插件都要封装才能使用,现在我的项目里的jq插件已经封装好,不过他们的版本并不是和官方同步的。如果按照现在的趋势,您觉得jq插件,要么全封装好,还是全使用shim插件好呢?我想选择一个稍微一劳永逸的方向:)

Chris Chen

unread,
Mar 10, 2013, 1:18:15 AM3/10/13
to se...@googlegroups.com

个人觉得应该封装,但实际可能还要取决于项目里插件数量和封装难易度

Frank Wang

unread,
Mar 11, 2013, 10:13:31 PM3/11/13
to seajs
@Km Van

考虑 shim 配置和 alias 配置的冗余,以及其他冲突,目前开发中的最新版本已经将 alias 配置和 shim 配置合并,变成:

alias: {

   jquery: {
      src: ...
      deps: ...
      exports: ...
   }
}



感谢反馈



2013/3/10 Chris Chen <me.ch...@gmail.com>



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

Km Van

unread,
Mar 12, 2013, 12:52:23 AM3/12/13
to se...@googlegroups.com
原来如此,明白了,谢谢协助:)
等2.0正式版,就用上下个项目,期待ing
Reply all
Reply to author
Forward
0 new messages