简体   繁体   English

如何使用JSPM使用缩小的第三方Javascript文件

[英]How to use minified third party Javascript files using JSPM

My application is using JSPM and SystemJS for module loading and is using angular. 我的应用程序使用JSPM和SystemJS进行模块加载,并使用angular。

My config.js file has angular map like: 我的config.js文件有角度图,如:

"angular": "github:angular/bower-angular@1.5.8"

So when I do import angular from 'angular' , I am getting the angular.js file from the Path specified in config.js file. 因此,当我import angular from 'angular'时,我从config.js文件中指定的Path获取angular.js文件。 That's good. 非常好。

Now the requirement is I want to use minified third party javascript files (angular.min.js) in the app. 现在要求是我想在应用程序中使用缩小的第三方javascript文件(angular.min.js)。 But there is no minified files in jspm registry 但是jspm 注册表中没有缩小文件
So the initial loading time of my application is high because of so many large files eg angular.js, browser.js etc. that takes too much time to load. 所以我的应用程序的初始加载时间很长,因为有很多大文件,例如angular.js,browser.js等需要花费太多时间才能加载。

I know, I can do a jspm bundle to minify all dependency files recursively which includes vendors' files also. 我知道,我可以做一个jspm bundle来递归缩小所有依赖文件,包括供应商的文件。 But my questions are: 但我的问题是:

1 - Is it possible to use vendor's minified file ( angular.min.js ) directly with JSPM? 1 -是否可以直接使用JSPM的供应商缩小文件( angular.min.js )? It is good to use vendor's minified file rather than minifying them ourshelves, Isn't it? 使用供应商的缩小文件而不是将它们缩小为自己是好的,不是吗?

2 - If above one is not possible, then how can I bundle only my application specific files and still able to use (bundle separately) minified angular.js file? 2 -如果上面的一个不可能,那么我如何只捆绑我的应用程序特定文件并仍然能够使用(单独捆绑)minified angular.js文件?

What is the recommended approach here? 这里推荐的方法是什么?

In your config.js file you can map any file with a name and have it imported by SystemJs in the browser 在config.js文件中,您可以使用名称映射任何文件,并在浏览器中由SystemJs导入

So you could potentially do something like 所以你可能会做类似的事情

"angular": "jspm_packages/...../angular.min" (The path to your file) “angular”:“jspm_packages /...../ angular.min”(文件的路径)

However the recommended approach would be to bundle and minify all your vendor files and as you mentioned, bundle your application specific files separately 但是,建议的方法是捆绑和缩小所有供应商文件,如您所述,单独捆绑您的应用程序特定文件

You can do this with something like Gulp or Grunt to generate the 2 files 您可以使用Gulp或Grunt之类的方法来生成2个文件

There are lots of examples online of how to do this but here is one to get you started https://blog.dmbcllc.com/using-gulp-to-bundle-minify-and-cache-bust/ 网上有很多关于如何做到这一点的例子,但这里有一个让你入门的例子https://blog.dmbcllc.com/using-gulp-to-bundle-minify-and-cache-bust/

Once you have generated both files you add them to your html page via a script tag 生成这两个文件后,可以通过脚本标记将它们添加到html页面

<script src="Your File Path"></script>

Option 2 is the preferred approach and I would recommend spending the time to get setup as you only have to do it one time to get your head around it 选项2是首选方法,我建议花时间进行设置,因为你只需要做一次就可以了解它

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

相关问题 如何使用缩小的javascript? - How to use minified javascript? 如何在Polymer 2.x中使用第三方JavaScript插件 - How to use third party javascript plugin in polymer 2.x 如何导入或使用javascript中第三方命名空间中定义的函数? - How to import or use functions defined in third party namespace in javascript? 如何使用Java发送和读取第三方javascript变量 - How to use Java to sent and read a third party javascript variables 如何在angular cli应用程序中使用typescript声明(.ts.d文件)来使用第三方javascript API / SDK? - How Do I use typescript declarations (.ts.d files) to consume a third party javascript API / SDK in an angular cli application? 如何使用 javascript 或 python 允许所有第三方在 chrome 中使用? - How to allow all third party in chrome using javascript or python? 在MVC中使用第三方JavaScript - Using third-party javascript in MVC 使用 JavaScript 禁用第三方 cookie - Disable third party cookies using JavaScript 如何使用第三方.flow文件? - How to consume third party .flow files? 如何在第三方网站上检测JavaScript事件 - How to detect javascript events on third party sites
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM