Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

直接使用模块名异步加载的时候加载失败 #16

Open
abramstyle opened this issue May 11, 2015 · 2 comments
Open

直接使用模块名异步加载的时候加载失败 #16

abramstyle opened this issue May 11, 2015 · 2 comments

Comments

@abramstyle
Copy link

模块其实已经定义好了,也用define包起来了,但是加载的时候也只是简单粗暴地用domain/modulename这样的路径去找模块,我是用错了还是async这个方法有问题?

@oxUnd
Copy link
Contributor

oxUnd commented May 11, 2015

没用错,mod.js 在产出的时候不是以一个完整的 loader 存在的,为了配合 fis 的包括md5、cdn等等功能,需要在加载使用时,给 mod.js 一个静态资源列表;这样才能加载到正确的结果;而这个列表是由后端通过查询 fis 产出的静态资源列表 map.json 得到的。

类似

require.resourceMap({
  "res":{
  "common:widget\/lib\/swfupload\/swfupload.js":     
    {
      "url":"http:\/\/cdn.iknow.bdimg.com\/static\/common\/widget\/lib\/swfupload\/swfupload_b24a26d.js"
    }
  },
  "pkg":[]
});

当页面中 require.async 某一个资源的时候,会先去从设置的 resourceMap 中查询这个资源的 url 再进行请求;

比如上面给的例子,如下加载这个组件。会去请求 http://cdn.iknow.bdimg.com/static/common/widget/lib/swfupload/swfupload_b24a26d.js 这个 url,得到结果;

require.async('common:widget/lib/swfupload/swfupload.js', function (xxx) {});

@abramstyle
Copy link
Author

OK,我也想着应该给require设置一个resourceMap才对,原来是这样设置的,多谢多谢。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants