简体   繁体   English

JSPM捆绑vs requireJs的困惑

[英]JSPM bundle vs requireJs confusion

I am new to jspm. 我是jspm的新手。 I have requrieJs background. 我有求职背景。

Is it true that jspm while bundling compiles all dependencies into one big file ? 捆绑时jspm将所有依赖项编译到一个大文件中是真的吗? like jquery, jquery-ui,bootstrap, databases to other 50 plguins used in project ? 像jquery,jquery-ui,bootstrap,数据库到项目中使用的其他50个plguins?

If yes, then What is benefit ? 如果是,那么有什么好处? would it not be much faster to fetch items when required like in requrieJs ? 像需要时一样,在需要时获取项目会不会快得多?

By default jspm does not bundle your dependencies. 默认情况下,jspm不会捆绑您的依赖项。 Every dependency is imported on its own. 每个依赖项都是独立导入的。 So if you have three files, say main.js, smth.js and jquery.js, jspm will require them one by one as soon as System.import is called. 因此,如果您有三个文件(例如main.js,smth.js和jquery.js),则在调用System.import时,jspm将一一要求它们。 For static dependencies (like ES6 modules), it happens before the code is executed. 对于静态依赖项(例如ES6模块),它发生在代码执行之前。 But you can also require additional modules at runtime. 但是您也可以在运行时需要其他模块。

The idea behind is that bundling is not really required with HTTP/2. 背后的想法是,HTTP / 2并不需要捆绑。 jspm knows the entire dependency tree and it can request all of the dependencies in parallel. jspm知道整个依赖关系树,它可以并行请求所有依赖关系。 Then all files will be delivered over the same network connection which should be pretty the same as if you were bundling them at the build time. 然后,所有文件都将通过相同的网络连接传递,这应该与在构建时将它们捆绑在一起时完全一样。

But since HTTP/1 is still to common, jspm offers bundle & build CLI. 但是由于HTTP / 1仍然很常见,因此jspm提供了捆绑和构建CLI。 But those command only put everything in one big file by default. 但是默认情况下,这些命令仅将所有内容放入一个大文件中。 The process is highly configurable. 该过程是高度可配置的。 You can exclude certain dependencies such as jquery and put them in a separate bundle or even load jquery from CDN. 您可以排除某些依赖项,例如jquery并将它们放在单独的包中,甚至可以从CDN加载jquery。 See https://jspm.io/docs/production-workflows.html#creating-a-bundle for more info how exclude/include modules. 有关如何排除/包含模块的更多信息,请参见https://jspm.io/docs/production-workflows.html#creating-a-bundle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM