Giter Site home page Giter Site logo

Comments (12)

lifesinger avatar lifesinger commented on June 3, 2024

用的是  0.9.0pre 版本吗?我这里未发现此问题,能否给个错误示例?

from seajs.

lifesinger avatar lifesinger commented on June 3, 2024

经过详细测试后,未能重现。请更新到 0.9.0 以上版本,感谢反馈。

from seajs.

zicjin avatar zicjin commented on June 3, 2024

再次测试后结果是这样的:
1.拥有module.exports定义的模块可以使用require('filename')调用,没有任何问题。
2.其他的模块如果使用require('filename')会有概率地出现加载失败,改用require('filename.js')后不存在此问题。
3. 0.9.0版同样如此。

from seajs.

lifesinger avatar lifesinger commented on June 3, 2024

能否提供测试页面?我排查了一下代码,未能找出有可能导致你说的问题的代码,很奇怪呢。

from seajs.

zicjin avatar zicjin commented on June 3, 2024

上传了一个demo包:
http://cid-2dcd432ec78904dc.office.live.com/self.aspx/pub/seajsdemo.rar

from seajs.

lifesinger avatar lifesinger commented on June 3, 2024

非常感谢 zicjin 提供测试包

仔细看了下,问题出在 require('jq.repurl')($); 需要修改成 require('jq.repurl.js')($)

原因是 seajs 里会认为 jq.repurl 的后缀是 .repurl, 对于已经有后缀的文件,不会再添加 .js, 因此 require('xx.zz') 这种带 . 的filename,需要手动添加 .js

这个问题两种规避办法:

  1. 当文件名中含有 . 时,记得添加 .js
  2. 去掉文件名中的 .

因为是浏览器端,无法去提前判断 fileIsExisted(filename), 很难找到两全的约定方式,知道了上面的规律就好。

from seajs.

lifesinger avatar lifesinger commented on June 3, 2024

dzлṩ԰˵
#33 (comment)

κ⣬ӭϵ

2011/5/21 zicjin <
[email protected]>

ϴһdemo
http://cid-2dcd432ec78904dc.office.live.com/self.aspx/pub/seajsdemo.rar

Reply to this email directly or view it on GitHub:
#33 (comment)

ƽ /

from seajs.

gyf19 avatar gyf19 commented on June 3, 2024
  1. 带.的js 文件还很多的, 觉得lifesinger应该判断一下。
  2. 有一种js 是由程序动态生成的, 它可以没有.js 扩展名, 例如: http://info.wyx.cn/ConfigJs.ashx

from seajs.

lifesinger avatar lifesinger commented on June 3, 2024

@gyf19:

嗯,就是考虑到了这种动态生成的 js 文件,所有不能简单粗暴的给所有文件都添加上 .js

对于带 . 的文件名,比如 xx.zz, 理想的处理逻辑是:

如果 .zz 是后缀,则不添加 .js
如果 .zz 只是文件名的一部分,才添加 .js

苦恼的就是在浏览器端,无法提前知道 .zz 是文件名的一部分,还是文件后缀。因此目前只能做如下取舍:

  1. 不管带不带 ., 都添加 .js, 这与 CommonJS 规范违背,同时也没有遵守 DRY
  2. 对于带 . 的文件,不添加 .js; 对于不带 . 的文件,才添加 .js

目前 seajs 的处理逻辑是第2种。暂时想不到更好的方式-.-

from seajs.

zicjin avatar zicjin commented on June 3, 2024

谢谢~~

from seajs.

zicjin avatar zicjin commented on June 3, 2024

我觉得得到一点点性能牺牲这点易用性是值得的,只是最好把这些细节在文档里做好

from seajs.

lifesinger avatar lifesinger commented on June 3, 2024

参考了下 flyscript 的处理逻辑,感觉比 seajs 的好:

对于 require(id)

如果 id 以 .js 结尾,则不再添加 .js
如果 id 以 # 结尾,也不添加 .js
其它情况下,一律添加 .js

这样,在大部分情况下,能按照使用者的预期运作。seajs 修改成了这个逻辑

from seajs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.