在单独的文件中包含所有脚本 [英] Including All Scripts In Separate File

查看:59
本文介绍了在单独的文件中包含所有脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

建立一个网站,我有许多脚本堆积起来.我在想,最好有一个单独的文件来包含"我的所有脚本,而不会使我的主要html代码混乱.

Making a site and I have a number of scripts piling up. I was thinking to myself it might be better to have a separate file to 'include' all my scripts without the clutter in my main html code.

这可能吗?人们用于这种事情的样式/方法有哪些?

Is this possible? What are some of the styles / methods people use for such a thing?

推荐答案

browserify requirejs 当前很流行捆绑库.

browserify, webpack and requirejs are currently some popular bundling libraries.

或者,您可以简单地将所有脚本串联到一个文件中,或者使用终端中的cat命令之类的东西,或者使用npm或 gulp ,然后将该文件包含在html中.使用npm,gulp或grunt之类的东西的好处是,您可以自动监视文件中的任何更改,并且当更改发生时,它将为您连接所有各种javascript文件.

Alternatively, you can simply concatenate all of your scripts into one file either manually using something like the cat command in your terminal, or automatically, by using npm or a task runner like grunt or gulp then just include that file in your html. The benefit of using something like npm, gulp or grunt is that you can automatically watch your files for any changes, and when changes occur, it will concatenate all your various javascript files together for you.

这篇关于在单独的文件中包含所有脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆