如何管理客户端 JavaScript 依赖项? [英] How to manage client-side JavaScript dependencies?
问题描述
尽管有很好的解决方案来管理服务器端的依赖项,但我找不到任何可以满足我对具有连贯客户端 JavaScript 依赖项管理工作流的所有需求的解决方案.我想满足这 5 个要求:
Although there are great solutions to manage dependencies on the server side, I could not find any that satisfies all my needs to have a coherent client side JavaScript dependency management workflow. I want to satisfy these 5 requirements:
- 以类似于 npm 的 package.json 或 bower 的
bower.json
- 它应该能够灵活地在我的
dependency.json
文件中指向 git repo 或实际的 js 文件(在网络上或本地),用于鲜为人知的库(npm 让你指向 git repos) - 它应该将所有库缩小并命名为一个文件,如 ender - 这是我唯一想要的 js 文件需要在客户端放入我的
标签
- 它应该像 BoxJS 一样对 CoffeeScript 提供开箱即用的支持4(现已失效)
在浏览器中,我应该可以使用 require 样式:
- Manage my client side dependencies in a format similar to npm's package.json or bower's
bower.json
- It should have the flexibility to point to git repo or actual js files (either on web or locally) in my
dependency.json
file for lesser known libraries (npm let you point to git repos) - It should minify and namespace all libraries into a single file like ender - that's the only js file I would need to put in my
<script>
tag in the client side - It should have out of box support for CoffeeScript like BoxJS4 (now dead)
In the browser, I should be able to use either require style:
var $ = require('jquery');
var _ = require('underscore');
或者更好的是,使用 headjs 风格:
Or better yet, do headjs style:
head.js(['jquery', 'underscore', 'mylib'], function($, _, mylib) {
// executed when all libraries are loaded
});
如果没有一个这样的单一工具存在,那么最好的工具组合是什么,即我可以使用诸如 之类的东西组合的工具链volo(或 grunt)?
If no one such single tool exists, what is the best combination of tools i.e. a tool-chain that I can combine using something like volo (or grunt)?
我已经研究了我在这里链接的所有工具,它们最多只能单独满足我的 3 个要求.所以,请不要再发布关于这些工具的信息.我只接受提供满足我所有 5 个要求的单个工具的答案,或者如果有人发布了多个此类工具的工具链的具体工作流程/脚本/工作示例,这些工具也满足我的所有要求.谢谢.
I have already researched all the tools I have linked to in here and they satisfy only upto 3 of my requirements at best individually. So, please don't post again about these tools. I would only accept an answer that provides a single tool that satisfies all 5 of my requirements or if someone posts a concrete workflow/script/working example of a toolchain of multiple such tools that also satisfies all my requirements. Thank you.
推荐答案
最近发布的另一个满足我所有标准的框架:http://duojs.org/(并且还支持将 CSS 等其他资源视为依赖项).
Another framework that satisfies all my criterion released recently: http://duojs.org/ (and also supports treating other resources like CSS as dependencies).
这篇关于如何管理客户端 JavaScript 依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!