{"action":"created","issue":{"url":"https://api.github.com/repos/ecomfe/esl/issues/40","labels_url":"https://api.github.com/repos/ecomfe/esl/issues/40/labels{/name}","comments_url":"https://api.github.com/repos/ecomfe/esl/issues/40/comments","events_url":"https://api.github.com/repos/ecomfe/esl/issues/40/events","html_url":"https://github.com/ecomfe/esl/issues/40","id":76609431,"number":40,"title":"requirejs 与 esl 加载 echarts 的问题","user":{"login":"Phinome","id":1940194,"avatar_url":"https://avatars.githubusercontent.com/u/1940194?v=3","gravatar_id":"","url":"https://api.github.com/users/Phinome","html_url":"https://github.com/Phinome","followers_url":"https://api.github.com/users/Phinome/followers","following_url":"https://api.github.com/users/Phinome/following{/other_user}","gists_url":"https://api.github.com/users/Phinome/gists{/gist_id}","starred_url":"https://api.github.com/users/Phinome/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Phinome/subscriptions","organizations_url":"https://api.github.com/users/Phinome/orgs","repos_url":"https://api.github.com/users/Phinome/repos","events_url":"https://api.github.com/users/Phinome/events{/privacy}","received_events_url":"https://api.github.com/users/Phinome/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-05-15T06:04:28Z","updated_at":"2015-05-18T01:43:59Z","closed_at":null,"body":"情况描述：\r\n\r\n在以下的两个DEMO中，用 esl 加载的 echarts ，虽然控制台报出 `'echarts/chart/line' not found (http status 404)` ，但是似乎并不影响啥，图表仍旧绘制；而用requirejs 加载的那个DEMO，报错不会绘制图表。\r\n\r\n说明：\r\n\r\n* esl , requirejs 皆是最新的 release 版本；\r\n* echarts 采用 echarts 提供的在线构建工具构建，AMD方式打包；\r\n\r\nesl：[http://blog.supertree.me/demo/line.html](http://blog.supertree.me/demo/line.html)\r\n\r\nrequirejs：[http://blog.supertree.me/demo/line-require.html](http://blog.supertree.me/demo/line-require.html)\r\n\r\n问题：\r\n\r\n* esl 里对 `require([Array],callback)`的处理是否是只要有一个依赖加载成功，即执行callback，前提条件是callback里只有一个`param`，且依赖都打包在一个文件里，就如DEMO中那样：\r\n```javascript\r\nrequire([\r\n    'echarts',\r\n    'echarts/chart/line'\r\n], function(ec) {\r\n   // code\r\n});\r\n```\r\n* 我看了一下规范，规范里只说依赖加载OK，就执行 callback，也没说非得依赖非得全部没问题，才执行 callback ，关于这点，上面的两个 DEMO 也能看出 requirejs 与 esl 处理方式也是不同的，所以想问问你们是怎么理解的？\r\n\r\nThat's all.\r\nThanks."},"comment":{"url":"https://api.github.com/repos/ecomfe/esl/issues/comments/102887983","html_url":"https://github.com/ecomfe/esl/issues/40#issuecomment-102887983","issue_url":"https://api.github.com/repos/ecomfe/esl/issues/40","id":102887983,"user":{"login":"errorrik","id":2851010,"avatar_url":"https://avatars.githubusercontent.com/u/2851010?v=3","gravatar_id":"","url":"https://api.github.com/users/errorrik","html_url":"https://github.com/errorrik","followers_url":"https://api.github.com/users/errorrik/followers","following_url":"https://api.github.com/users/errorrik/following{/other_user}","gists_url":"https://api.github.com/users/errorrik/gists{/gist_id}","starred_url":"https://api.github.com/users/errorrik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/errorrik/subscriptions","organizations_url":"https://api.github.com/users/errorrik/orgs","repos_url":"https://api.github.com/users/errorrik/repos","events_url":"https://api.github.com/users/errorrik/events{/privacy}","received_events_url":"https://api.github.com/users/errorrik/received_events","type":"User","site_admin":false},"created_at":"2015-05-18T01:43:59Z","updated_at":"2015-05-18T01:43:59Z","body":"对于async require，必然是所有的modules都成功加载，才会执行callback的。这点不容置疑。\r\n\r\n你给的case中，细节是这样的：\r\n\r\n1. Array中包含两个modules，所以同时发出了请求\r\n2. `echarts/chart/line`模块对应的url资源不存在，所以报出了404错误\r\n3. `echarts`模块对应的资源中，不单包括自身定义，还包括了`echarts/chart/line`等模块及其依赖模块的定义。这个资源是一个打包的资源。所以当它返回的时候，`echarts`和`echarts/chart/line`都ready了。此时callback触发调用。\r\n\r\n所以建议对于线上环境，在async require之前，在页面中（after loader的位置）通过显式的`<script src=\"echarts.amd.js\"></script>`来引用echarts，这样当你`require(['echarts','echarts/chart/line']`时，loader知道这俩模块已经存在，就不会再发起请求。该方法对于amd loader应该都有效。\r\n\r\n另外，requirejs为什么不能绘制图表呢？我个人猜测是echarts中复杂的依赖关系导致requirejs分析和处理失败。具体失败在哪个点，暂时没时间去分析。"}}