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

relative2absolute 的问题 #58

Closed
nighca opened this issue Mar 18, 2016 · 5 comments
Closed

relative2absolute 的问题 #58

nighca opened this issue Mar 18, 2016 · 5 comments

Comments

@nighca
Copy link
Member

nighca commented Mar 18, 2016

RT,relative2absolutebaseId 值为形如 "http://..." 的字符串时,返回结果中的 // 会只剩一个,即:

relative2absolute('./a', 'http://baidu.com/b') // 返回结果为 "http:/baidu.com/a"

这个表现为在全局环境以完整 url 的形式加载匿名模块时,如果该模块有相对路径的依赖,则该依赖的路径会计算错误。

require(['http://baidu.com/xxx'], function(m){console.log(m)}) // `http://baidu.com/xxx` 内部有相对路径依赖

主要原因是在这里对 seg 对了非空的判断,不知道这是出于什么考虑。

@errorrik
Copy link
Contributor

baseId预期是一个module id而不是url

esl是不支持require([])一个url的,这不是标准amd的部分。在requirejs里是支持的,这是一个suger。

在开发应用的时候以模块的视角去考虑整体结构会更自然些

@Phinome
Copy link

Phinome commented Mar 22, 2016

按照规范来说,全局的 require 需要的是一个绝对的模块名称,而不是相对于另一个模块的 ID。AMD Require 定义,不知道这样理解是否合适

@nighca
Copy link
Member Author

nighca commented Mar 22, 2016

@errorrik 所以当需要加载一个外站模块,合适的做法是先通过 config 配置 pathpackages,然后使用 moduleId 去 require([moduleId]) 这样吗?

@errorrik
Copy link
Contributor

errorrik commented Apr 5, 2016

是的,标准做法是这样的。如果是非amd模块,需要配个shim

@nighca
Copy link
Member Author

nighca commented Apr 5, 2016

👌 感谢 erik 大神回复~

@nighca nighca closed this as completed Apr 5, 2016
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

3 participants