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

async依赖打包进pkg目录 #21

Open
haledeng opened this issue Sep 7, 2015 · 6 comments
Open

async依赖打包进pkg目录 #21

haledeng opened this issue Sep 7, 2015 · 6 comments

Comments

@haledeng
Copy link

haledeng commented Sep 7, 2015

loader已经把页面的同步和异步依赖分析出来了,那么其他的插件有办法使用这个依赖项的map表了?

@2betop
Copy link
Contributor

2betop commented Sep 7, 2015

所有打包阶段的插件都能拿到 map 表,其实也不是 laoder 分析出来的,在打包前就分析出来了, loader 只是基于这些信息,自动把 js 和 css 插入到 html 文本里面。

@haledeng
Copy link
Author

haledeng commented Sep 7, 2015

require.resourceMap({
"res": {}, "pkg":{}
});

这个html的依赖的异步js不是loader分析出来的么?

@haledeng
Copy link
Author

haledeng commented Sep 7, 2015

另外这里asyncs的文件怎么没有打包了?

@2betop
Copy link
Contributor

2betop commented Sep 7, 2015

打包分两种:

  1. 用户自己配置什么文件打包到什么文件,可以结合match 设置 packTo 即可。
  2. 完全有 loader 根据页面使用情况分析,把用到的资源 allInOne 打包,这里你提到了异步依赖没有打包的问题,的确默认不是这种模式,可以设置 includeAsyncs 来包含异步依赖部分。

关于以上两种打包方式各有优缺点:

  1. 比较灵活,完全自己控制,可以做到页面与页面之间公用部分独立打包,保障缓存利用率。
  2. 使用简单,但是公用的部分被打包到了每个页面里面。

@haledeng
Copy link
Author

haledeng commented Sep 8, 2015

  1. includeAsyncs 这货不是被注释了吗?
  2. 考虑同步资源 allInOne 的同时,资源是否也直接 allInOne?这样开发不需要关注require, require.async打包的问题。在你的pack.js文件里面试着加上下面的语句,是可行了(loader的功能还是很强大的)。但是这里有一个引入的问题,即如何引入这个异步的JS。粗暴的逻辑是:同步js加载完成后,就直接加载异步js(预加载),可以放在html 里面,也可以在同步js中require加载
pack(resource,asyncs, 'pkg/${filepath}_async.js');

个人观点,欢迎指正。

@2betop
Copy link
Contributor

2betop commented Sep 8, 2015

includeAsyncs 只是个配置项,默认不开启,当然就在源码配置项里面注释掉了。个人认为,如果异步资源比较多,可以考虑开启此功能。

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