{"action":"created","issue":{"url":"https://api.github.com/repos/fex-team/fis3/issues/83","labels_url":"https://api.github.com/repos/fex-team/fis3/issues/83/labels{/name}","comments_url":"https://api.github.com/repos/fex-team/fis3/issues/83/comments","events_url":"https://api.github.com/repos/fex-team/fis3/issues/83/events","html_url":"https://github.com/fex-team/fis3/issues/83","id":95617292,"number":83,"title":"关于 fis3 中打包配置讨论，邀请大家来讨论。","user":{"login":"2betop","id":2698393,"avatar_url":"https://avatars.githubusercontent.com/u/2698393?v=3","gravatar_id":"","url":"https://api.github.com/users/2betop","html_url":"https://github.com/2betop","followers_url":"https://api.github.com/users/2betop/followers","following_url":"https://api.github.com/users/2betop/following{/other_user}","gists_url":"https://api.github.com/users/2betop/gists{/gist_id}","starred_url":"https://api.github.com/users/2betop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/2betop/subscriptions","organizations_url":"https://api.github.com/users/2betop/orgs","repos_url":"https://api.github.com/users/2betop/repos","events_url":"https://api.github.com/users/2betop/events{/privacy}","received_events_url":"https://api.github.com/users/2betop/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-07-17T09:00:09Z","updated_at":"2015-08-04T12:31:23Z","closed_at":null,"body":"当前配置 API 规则是这样的。\r\n\r\n```js\r\nfis.match('/target/**.js', {\r\n  packTo: 'pkg/target.js'\r\n});\r\n```\r\n\r\n当 target 中要控制打包顺序的时候，需要通过配置 match 顺序来控制。\r\n\r\n如：\r\n\r\n```js\r\nfis.match('/target/a.js', {\r\n  packTo: 'pkg/target.js'\r\n});\r\n\r\nfis.match('/target/**.js', {\r\n  packTo: 'pkg/target.js'\r\n});\r\n```\r\n\r\n这样打包的 `pkg/target.js` 会先打包 `/target/a.js` 然后是其他命中的文件。\r\n\r\n虽然能解决问题，但是感觉还是不优雅，为了精确的控制顺序，会有很多个 match方法，项目大了，配置文件也会特别的多。\r\n\r\n于是，想到了 **方案1：让 `fis.match` 支持数组。**\r\n\r\n```js\r\nfis.match([\r\n    '/target/a.js',\r\n    '/target/**.js'\r\n  ], {\r\n  packTo: 'pkg/target.js'\r\n});\r\n```\r\n\r\n但是这样或许让 match 看起来很乱。也许像以前那样配置**方案2**可能更好理解。\r\n\r\n```js\r\nfis.pack('pkg/target.js', [\r\n  '/target/a.js',\r\n  '/target/**.js'\r\n]);\r\n```\r\n\r\n所以，这里请大家来看看，哪种配置方式更好。\r\n\r\n另外：关于依赖是否打包进来的优化，在 fis2 中开发了个 [depscombine](https://github.com/fex-team/fis-packager-depscombine)，发现也有不少用户喜欢用这种方式，能自动把同步依赖打包进来。但是有时又希望能和原来的不包含依赖的打包方式结合。\r\n\r\n于是，想到了一种方式，就是新加伪类用法。`:deps` 和 `:asyns` 分别用来匹配目标文件的同步依赖和异步依赖。\r\n\r\n\r\n```js\r\n// 方案1：\r\nfis.match([\r\n  '/compA/main.js',\r\n  '/compA/main.js:deps',\r\n  '/compA/main.js:asyncs',\r\n\r\n  // 排除掉 common.js 中的依赖\r\n  '!/compA/common.js:deps'\r\n], {\r\n  packTo: '/pkg/compA.js'\r\n})\r\n```\r\n\r\n```js\r\n// 方案2：\r\nfis.pack('pkg/compA.js', [\r\n  '/compA/main.js',\r\n  '/compA/main.js:deps',\r\n  '/compA/main.js:asyncs',\r\n\r\n  // 排除掉 common.js 中的依赖\r\n  '!/compA/common.js:deps'\r\n]);\r\n```\r\n\r\n由于这种伪类只能在打包期实现，所以只能在配置打包的时候才有用。所以考虑到伪类的支持，个人偏向与配置方案2，即用 `fis.pack`, 就是怕用户把这种伪类，用于其他地方配置。"},"comment":{"url":"https://api.github.com/repos/fex-team/fis3/issues/comments/127585403","html_url":"https://github.com/fex-team/fis3/issues/83#issuecomment-127585403","issue_url":"https://api.github.com/repos/fex-team/fis3/issues/83","id":127585403,"user":{"login":"fouber","id":536297,"avatar_url":"https://avatars.githubusercontent.com/u/536297?v=3","gravatar_id":"","url":"https://api.github.com/users/fouber","html_url":"https://github.com/fouber","followers_url":"https://api.github.com/users/fouber/followers","following_url":"https://api.github.com/users/fouber/following{/other_user}","gists_url":"https://api.github.com/users/fouber/gists{/gist_id}","starred_url":"https://api.github.com/users/fouber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fouber/subscriptions","organizations_url":"https://api.github.com/users/fouber/orgs","repos_url":"https://api.github.com/users/fouber/repos","events_url":"https://api.github.com/users/fouber/events{/privacy}","received_events_url":"https://api.github.com/users/fouber/received_events","type":"User","site_admin":false},"created_at":"2015-08-04T12:31:23Z","updated_at":"2015-08-04T12:31:23Z","body":"1. match不要支持数组，或者说即便支持数组也不是拿来干这件事的，这个潜规则太黑盒了\r\n2. 用户不关心你的真实打包排序，所以问题的关键取决于打包插件的实现\r\n\r\n先考虑一个问题：什么情况下会出现不正确的顺序？\r\n\r\n相信现在package插件的实现绝对解决了有明确依赖关系的资源之间的打包顺序问题，唯一有错误的情况就是一个包里合并了两棵或以上独立的依赖树，而这些依赖树之间有运行时的依赖关系却没有被标记出来，才有了报错。\r\n\r\n最常见的情况就是jquery被当做全局函数直接使用，并且和其他模块化资源打包在一起，模块化资源并不会显式的声明对jquery的依赖，导致可能出现打包顺序错误的问题。\r\n\r\n另外一种情况就是由于平台原因读取文件的顺序不同，使得相同的代码打包顺序不同，导致构建结果不一致的问题（插件内部排一下序就好了，或者获取所有文件的时候就排一次序）。\r\n\r\n第一个问题我觉得可以让package插件支持读取文件对象的 ``packOrder`` 参数，默认都是-1（排在最后），如果有其他值就向前排序。"}}