首页 国际新闻正文

拍照软件,译:NPM 与前端包办理,卫星

We've known for a while that front-end asset and dependency management is a huge use-case for npm and a big driver of Node.js adoption in general. But how big, exactly? It's a hard question to answer. The list of most-downloaded packages on npm is not very helpful: packages like async, minimist and request are the bread-and-butter packages that are depended upon by thousands of other packages, so of course they get ins摄影软件,译:NPM 与前端包处理,卫星talled and downloaded all the time as part of the installations of those packages.

咱们很清楚,前耶塞拉的菌丝外套端资源及其依靠处理一直是 npm 的重度运用场景,一同这也一直是 Node.js 遍及的重要推动力。但这类运用场景到底有多重度?这是一个很难答复的问题。这份 “npm 最常下载的包的清单” 并不能供给有用的依据:由于像 async、minimist 和 request 这样的包就像是 “生活必需品”,它们会被数以千计的其它包所 依靠,这样一来它们当然会跟着那些依靠它们的包一同被不停地下载。

A more interesting and revealing question is: what packages do people explicitly install? By which we mean, how many times did somebody (or some robot) actually run the command npm install thispackage? We recently started plugging our log data into Jut, which has made it easy and quick to answer these questions for the first time. The resulting list of the top 50 explicitly-installed npm packages is very different and very interesting. 32% of the packages in the top 50 (and 50% of the actual downloads) are front-end tools or frameworks, with Grunt, Bower and Gulp leading the pack (mobile is also a huge use-case, and we'll be talking about it in a later blog post). Plus, usage of all these packages is growing steadily:

更有意义也更挨近本相的问题是:哪些包是人们主动装置的?所谓 “主动装置”,便是指某个人(或某个机器人)以实践运转 npm install thispackage 指令的办法来装置一个包。不久前,咱们开端把日志数据加入到 Jut 中,随后咱们总算能够便利而快速地给出这个问题的答案了。终究,咱们得到了 “最常主动装置的 npm 包五十强榜单”,这份榜单画风骤变,很有意思。在五十强中有 32% 的包(它们发作了 50% 的实践下载量)都是前端的东西或结构,携 Grunt、Bower 和 Gulp 一同遥遥领先(当然移动端也是一大重度运用,这儿暂且不表)。此外,这些包的运用量也在稳步增加:

(客户端东西的增加,2014 年 1 月~10 月)

The other way we know front-end is a huge use-case is that we get a lot of questions (and issue reports) from users of npm and web developers about how best to use npm to manage client-side dependencies. These questions often have some incorrect assumptions that are strange to us, so let's be big and bold about refuting them:

另一个途径也佐证了前端是重度运用场景的这一现实——咱们从 npm 用户和 web 开发者那里收到了许多关于怎么用 npm 来处理好客户端依靠的发问(和毛病反应)。这些问题一般都伴有极端片面的成见,令咱们感到适当惊讶。好吧,那就让咱们郑重其事地来弄清一下:

1. "npm is only for CommonJS!"

1. “npm 仅仅为 CommonJS 服务的!”

Not true. npm would like to be the package manager for JavaScript, so if it's JavaScript related, the npm registry is a good place to put it. Node.js provides a CommonJS-esque module environment, but npm has no feelings on the matter.

不对。npm 期望成为 JavaScript 的包处理器,因而,只需是跟 JavaScript 相关的,都适宜放入 npm 的包库房(registry)。虽然 Node.js 供给了一个 “CommonJS 式” 的模块环境,但 npm 对此并不关怀。

2. "npm is only for server-side JavaScript!"

2. “npm 仅仅为服务器端的 JavaScript 服务的!”

Also not true. Your package can contain anything, whether it's ES6, client-side JS, or even HTML and CSS. These are things that naturally turn up alongside JavaScript, so put them in there.

相同不对。你的包能够包括任何内容,不论是 ES6、客户端 JS,仍是 HTML 和 CSS。有许多东西天然生成便是跟 JavaScript 绑在一同的,那就把它们都放进来吧。

npm's code of conduct defines a very short list of things we don't think are appropriate to put in packages (TLDR: don't use us as your database, or your media server) but if in doubt, just ask us on Twitter or email and we'll be happy to weigh in.

npm 的 《行为准则》 总结了一份十分简略的列表,列出了咱们以为不适宜放进包里的东西(简略来说:不要把 npm 当摄影软件,译:NPM 与前端包处理,卫星作你的数据库或多媒体服务器来用)。对此如有疑问,请经过 Twitter 或 Email 问询,咱们乐于谈论。

npm's philosophy

npm 的哲学

npm's core value is a desire to reduce friction for developers. Our preferred way to do this is by paving the cowpaths. That is to say: we don't like to tell you what to do. We like to find out what you're doing, and then get the obstacles out of your way. If lots of people are doing different things, we try to avoid picking a winner until it's obviously the best.

npm 的愿景是协助开发者削减抵触。咱们倾向于经过 “循踪辟径” 的办法来完成这一点。这句话的意思是说:咱们不期望告知用户该怎样做;咱们期望调查用户是怎样做的,然后把妨碍扫清。假如许多人都是在以各自不同的办法在行事,那咱们不会轻易地从中挑出一个胜者,除非最佳实践现已昭然若揭。

So, when it comes to front-end packages, where is the friction, and what are the cowpaths?

那么,在前端包处理的范畴中,用户遇到的阻力终究在哪里?用户踩出的 “踪” 又是怎样的?

Front-end pain points

前端痛点

In addition to GitHub issues and users on IRC, Twitter, conferences and meetups, we've also spoken directly to developers on some of the bigger frontend packages like Angular and Ember (both of which are also in the top 50). They didn't all agree on solutions but their pain points were roughly in common. Let's look at them, and then talk about how to tackle them:

除了 GitHub issue 以及 IRC、Twitter、技能会议和线下聚会中的用户以外,咱们还会跟一些大型前端包的开发者们直接对话——这其间包括 Angular 和 Ember 的开发者(这两者都位列五十强)。他们在处理计划上并不彻底一致,但他们的痛点却是大体相同的。接下来咱们会逐个打开,并谈论怎么霸占这些难题:

1. node_modules isn't arranged the way front-end packages need it to be

1. node_modules 目录并不是依照前端包所需求的办法来安排的

This is a pretty obvious 摄影软件,译:NPM 与前端包处理,卫星problem. The node_modules folder is where npm puts packages by default, to take advantage of the Node.js module loading semantics. Depending what packages you install, packages end up in different places in the tree. This works great for Node, but HTML and CSS, for better or worse, generally expect things to be in one location, like /static/mypackage. There are workarounds for this to be sure, but no first-class solution yet.

这是一个十分显着的问题。node_modules 目录是默许状况下 npm 寄存包的当地,它得名于 No网游之圣匠de.js 的模块加载行为。依据你装置的包的具体状况,全部包终究会被寄存在目录树的不同方位。这关于 Node 来说全部杰出,但关于 HTML 和 CSS 来说,不管怎样,咱们一般都期望全部东西能够汇总在同一个当地,比方 /static/mypackage 这样的目录下。必定有一些变通办法能够绕过这个问题,但还算不上是最佳计划。

2. Front-end dependencies have西安市长安区天气预报 different conflict-resolution needs

2. 前端依靠在处理抵触方面具有天壤之别的需求

One of the joys of the Node module loader is that it allows you to have multiple, incompatible versions of the same module present at the same time, and the one of the joys of npm is that it puts these versions into the right places so that the version you were expecting gets loaded where you expected it. This goes a long way towards eliminating "dependency hell" and is one of the reasons Node's "many small modules" pattern is so practical and so popular.

Node 模块加载器的一个有意思的当地在于,它答应你一同运用同一个模块的多个不兼容版别;而 npm 的一大有意思的当地在于,它能够将包的这些不同版别放置在适宜的当地,然后做到在想要的当地加载想要的版别。这种办法关于防止 “依靠阴间” 有很大协助,一同这也是 Node 的 “许多小模块” 的实践形式如此有用且盛行的原因之一。

But front-end dependencies simply don't work this way. If you load two versions of jQuery one will "win". If you load two versions of the Bootstrap CSS framework they will both apply simultaneously and wreck your styling. In the future, new developments in HTML like web components and Shadow DOM may help resolve these problems, but at the moment, front-end dependencies can conflict. How do we recognize and handle that gracefully?

但前端依靠却是无法以这样的办法来运作的。假如你在网页中一同加载两个版别的 jQuery,那其间只需一个会 “胜出”。假如你一同加载了两个版别的 Bootstrap CSS 结构,它们会一同起作用,然后把页面款式搞得一团糟。在未来,HTML 将取得新的特性(比方 web components 和 Shadow DOM),或许有助于处理这类问题;但在眼下,前端依靠会发作抵触。那咱们怎么高雅地判别并处理这个难题呢?

3. Maintaining multiple package manifests is annoying

3. 一同保护多个包清单是很烦人的

The solution to the previous problems has been to create additional registries for front-end packages, but this has created a situation where a single project must have a package.json, a bower.json, a component.json, and so on, and edit them all every time even a minor update happens. Like all data duplication, this is tedious and error-prone.

前两个问题其完成已有了一种处理计划,便是为前端包额定装备其它的包处理计划。但这会发作这样一种局势——单个项目可能会一同包括一个 package.json 文件、一个 bower.json、一个 component.json 等等。每逢遇到哪怕是一丁点儿更新时,你都要把全部这些装备文件统统修改一遍。跟全部的数据冗余相同,这种景象不只烦人,并且简略发作过错。

4. Finding browser-compatible pack第五影院ages is a pain

4. 找到兼容浏览器的包很苦楚

npm is 摄影软件,译:NPM 与前端包处理,卫星the registry for JavaScript, but at the moment most of what's in the registry is Node.js. Some of those modules work when adapted for clients using modules like browserify, but some of them don't. At the moment there's no way to easily find out which do and which don't without trying them out.

npm 是为 JavaScript 服务的包库房,但现在库中绝大多数的包都是 Node.js 包。在选用 Browserify 等东西做过适配之后,某些模块是能够在客户端运转的,但还有许多依然是不可的。现在,假如要判别某个包是否在浏览器端可用,除了实测,好像还没有一种简略易行的办法。

Front-end solutions

前端处理计划

With those four problems in mind, let's talk about how we can solve them.

在找出了以上四个难题之后,让咱们来逐个谈论怎么处理。

The final problem mentioned is the easiest to tackle, and we have already started laying the groundwork for the solution: ecosystems.

上面说到的终究一个难题是最简略战胜的,咱们现已开端为处理计划奠定根底了。这个处理计划便是:生态圈。

Ecosystems are searchable subsets of the registry, defined by programmatically filtering all the packages in the registry according to some criteria like "works in a browser" or "runs on Windows" or "is compatible with Express" or a million other possibilities. Once launched, one ecosystem will definitely be "browserify compatible", and other definitions of "client-side friendly" will definitely be implemented as well. We're really optimistic that this will be a great solut按着李娜ion, which leaves us with the first three, harder problems.

生态圈是指包库房的一些可查找的子集,这些子集是经进程序化地挑选库中的全部包而发作的,挑选条件是比方 “可在浏览器中运转” 或 “可在 Windows 上运转” 或 “兼容 Express” 等数以百万计种可能性。此功用一旦上线,必将会有一个叫作 “兼容 Browserify” 的生态圈,而其它称号比方 “对客户端友爱” 也必定会呈现。这将是一个十分棒的处理计划,咱们对此十分达观。接下来,让咱们着手处理剩余的三个难题。

Client-side package installation and dependency resolution

客户端的包装置与依靠解析

The third problem – multiple sets of package metadata – is a side-effect of solutions to the first two. People have written third-part强制绝顶y tools to solve the problems of installation and dependency resolution for client-side packaging, and while doing so they have often created their own independent package registries and metadata formats. There are a whole bunch of these solutions, each with their own pros and cons. But, as you can see from our usage data the most popular solution by far is Bower. So with apologies to the great ideas in the other package managers, we're going to focus on what Bower does.

第三个问题摄影软件,译:NPM 与前端包处理,卫星——多套包处理体系——实践上是前两个问题的副作用。现在现已有一些第三方东西企图缓解客户端的包装置和依靠解析问题,它们一般需求树立各自独立的包库房和装备文件格局。这类处理计划层出不穷,每一种处理计划都有其利益和矮处。不过,从上面的统计数据中能够看出,现在为止,在这方面最盛行的处理计划是 Bower。那么接下来,请答应咱们暂时疏忽其它优异的包处理器,要点重视一下 Bower 是怎么作业的。

Bower's solution

Bower 的处理计划

Bower can install packages by name, from Git URLs, or from arbitrary HTTP URLs, just like npm. Unlike npm, they are all installed into a single, flat directory structure under bower_components, e.g. if backbone requires underscore, bower install backbone puts both backbone and underscore into bower_components directly. This means referring to a component from a web app is very simple, because it will always be installed in the same place, unlike npm, where your exact install path can vary.

Bower 能够经过称号来装置包,也能够经过 Git URL 或恣意 HTTP URL 来装置,这些都跟 npm 是相同的。但跟 npm 不同的是,Bower 会把每个包都装置到 bower_components 目录下的独立目录中,整个目录结构是扁平的。举例来说,假如 backbone 依靠 underscore,那么 bower install backbone将会把 backbone 和 underscore 这两者都放置在 bower_components 目录下。这意味着,从一个 web 运用中引证一个组件是十分简略的,由于它总是会被装置在相同的当地——这跟 np初中女生胸好软m 不同,由于 npm 包的实践装置途径并不固定。

This flat package struct刘东强在美ure means that if you attempt to install two incompatible versions of the same library – say, jQuery 1.11.1 and 2.1.1 – they attempt to install to the same location, and conflict. If this happens, Bower asks you to manually select which one you prefer, and can optionally persist this selection to bower.json. This is nondeterministic, in that it relies on a human decision, so two people installing the same packages can end up with different sets of packages. But once you persist your selections to bower.json it is consistent – anybody installing your project will get the same packages.

扁平的目录结构存在一个问题,假如你企图装置同一个库的两个不兼容版别(比方 jQuery 的 1.11.1 版和 2.1.1 版)时,它们将会被装置到相同的方位,并发作抵触。假如发作了这种状况,Bower 会要求你手艺挑选哪个版别是你想要的,并且能够决议是否把这次挑选的成果保存到 bower.json 文件中。这个进程存在不确定要素,它依靠人工干预,因而两个人在装置相同的依靠包时可能会得出不同的装置成果。不过一旦你把你的挑选成果保存到了 bower.json 中,就不存在变数了——任何人在装置你的项目时都会得到相同的装置成果。

The user experience is not as good as Node land, where conflicts can be resolve摄影软件,译:NPM 与前端包处理,卫星d without user intervention. However, it addresses the concerns of front-end developers and clearly works well enough.

这种体会没有 Node 环境那么好,由于后者遇到的版别抵触能够在无需人工干预的状况下主动处理。总的来说,它照料到了前端开发者的重视点,并且它的确也干得挺不错的。

Reducing friction without picking a winner yet

现在还无法选出胜者,但咱们仍是想削减抵触

We don't want to get ahead of ourselves. While Bower is clearly popular, there are a lot of other packaging solutions out there right now. Browsers continue to evolve rapidly, so it doesn't seem to us that now is the right time to bless a single way of handling front-end packaging. This is where the strategy we previously outlined in the npm command-line interface roadmap comes in.

咱们并不想急于求成。虽然 Bower 现已十分盛行了,但眼下依然还有不少其它的包处理计划可用。一同,浏览器也在持续地快速演进,因而咱们以为,现在就对前端包处理计划下结论还为时过早。正是根据这种考量,咱们不久前在《npm 指令行界面(CLI)线路图》一文中提出了以下重要战略。

The plan for the npm CLI is to modularize it into discrete pieces that can be used independently and programmatically, not just as part of the npm client. The underlying goal is to make it possible for other people to write tools that re-use the parts of npm that work for them, and be able to implement their own solutions for the parts that don't, without turning npm into a gigantic ball of configuration options, switches, and lifecycle hooks.

咱们计划把 npm CLI 模块化,将其规划为各个别离的部件。这些部件不只作为 npm 客户端的一部分而存在,还能够独登时被程序所调用。底层的方针是令其别人能够在 npm 这个根底之上编写东西——假如 npm 中已有对他们有用的部件,那他们就能够重用;假如没有,他们也能够自行完成自己的处理计划。完成这个方针的办法,并不是把 npm 改形成装备选项、开关、生命周期钩子所组成的一坨大杂烩,而是将其模块化。

The exact design of a modularized CLI isn't finalized, but the big pieces would obviously include:

模块化 CLI 的完好规划还未定稿,但显然会包括以下几大部比你打又点件:

  1. a API for downloading packages from the registry
  2. a "cache" API that can s鹿关同寝tore, read and unpack packages locally
  3. an installer API that places packages into your project in the right location
  4. 一个用来从包库房中下载包的 API
  5. 一个能够在本地存储、读取并且解压缩的 “缓存” API
  6. 一个装置器 API,能够把包放置到你的项目中的适宜方位

It's pretty clear from what we've already said that any front-end package manager would probably want to use parts 1 and 2 and re-implement 3.

咱们应该现已说得十分清楚了,信任任何前端包处理器都想用上第 1 和第 2 条,然后从头完成第 3 条。

Building your own front-end package management using npm

运用 npm 来构建你自己的前端包处理体系

If you were to build the ideal front-end package management system today, what would that look like?

假如你打算在今日构建一个抱负的前端包处理体系,那它会是什么姿态的呢?

Here's the medium-term future of client-side package management as we see it:

中期来看,咱们所能想像到的官户端包处理体系将是这个姿态的:

1. Don't run your own registry, use ours

1. 别去运营你自己的包库房了,直接用咱们的

This isn't (just) self-interest: the feedback we get from literally everybody else running package registries right now is that they don't want to do it anymore. It's expensive, difficult and time-consuming to maintain the kind of uptime, performance, and user support that is required. And in any case, "hosting packages" is not the problem that client-side package managers are trying to solve. If it's JavaScript-related, host it in npm. Once they are available, use ecosystems to crea储组词te "mini-registries" within the global one, complete with custom search indexing and display characteristics.

这并不仅仅自私自利:除了咱们之外,还有一些人在运营着自己的包库房,但他们给咱们的反应都是再也不想持续下去了。保持包库房的安稳、高效、以及必要的客户支撑都是十分贵重、困难和消耗时刻的。并且从任何意义上来说,“保管包” 都不是客户端包处理器想要处理的问题。假如包是跟 JavaScript 相关的,那就保管到 npm 吧。一旦生态圈功用上线之后,就能够经过它来在大局库中创立 “微型库”,经过自定义查找的索引来充分其内容,并显现其特征。(译注:我其实不确定后半句在说什么。)

2. Use package.json for metadata

2. 选用 package.json 作为装备文件

If your tool needs metadata to make it work, put it in packagechinese帅哥.json. It would be rude to do this without asking, but we're inviting you to do it, so go ahead. The registry is a schemaless store, so every field you add is on an equal footing to all the others, and we w何炅的老婆儿子相片on't strip out or complain about new fields (as long as they don't conflict with existing ones).

假如你的东西需求一些装备信息才干作业,那就把它放进 package.json 文件中吧。好像未经问询就这样做稍显粗鲁,但咱们在此宣布约请:但做不妨。npm 的包库房是一个无形式约束的(schemaless)存储空间,因而你增加的每个字段都具有和其它字段相同的位置,咱们既不会铲除这些新字段,也不会由于存在新字段而报错(只需新字段没有跟现有的字段抵触就行)。

We realize this runs the risk of creating a jumble of incompatible metadata, so be reasonable: resist the temptation to grab a generic field name like "assets" or "frontend". Use a label摄影软件,译:NPM 与前端包处理,卫星 specific to your application, such as "mymanager-assets" or "mymanager-scripts". If in the future we decide to m蛇妃带蛋跑ore explicitly support your functionality and give it a generic field, it's easy to maintain backwards-compatibility with the old name.

咱们也意识到这可能会带来一种危险,发作一堆互不兼容的装备信息,因而,请适度运用:千万要抵挡住引诱,不要企图抢占一些通用的字段名,比方 "assets" 或 "frontend" 等等。用一个特定的、代表你的运用的标签就好,比方 "mymanager-assets" 或 "mymanager-scripts"。在未来,假如咱们决议愈加清晰地支撑你的功用,并为你分配一个通用字段,那也是很简略完成对旧字段名的向后兼容的。

3. Use our cache module

3. 选用咱们的缓存模块

Unpacking, storing and caching packages is a surprisingly complicated problem at scale. Especially if you are using our registry, once it becomes available, you should be using our cache module. This will save you effort, time, and bandwidth.

在规模化的状况下,解压缩、存储并缓存包其实是一个十分杂乱的问题。因而,假如你是在运用咱们的包库房的话,那么一旦缓存模块可用,你就应该当即用上它。它将会节约你的精力、时刻和带宽。

4. Write your own front-end semantics

4. 编写你自己的前端包行为

This is where your use-case differs from npm's Node-centric behavior, so this is the only bit you should need to write yourself. Even then, we should have some handy modules that will help you out. You could do like Bower does, and download and install front-end packages into a totally different folder and handle dependencies separately. Or you could get npm to install everything into node_modules and use a post-install or a run-time hook to resolve dependencies, or some combination of those strategies. We're not sure the best way to go, which is why we want to encourage experimentation here.

你的运用场景必定跟 npm 以 Node 为中心的行为截然不同,因而这是唯逐个块你需求自己搞定的部分。即便如此,咱们仍是会供给一些随手的模块来协助你。你能够做到和 Bower 相同的作用,比方把前端包下载并装置到一个彻底不同的目录中,然后自行处理依靠联系。或许你能够让 npm 把全部东西都装置到 node_modules 目录中,然后运用一个 post-install 脚本或一个运转时钩子来解析依靠,或以上战略的某种组合。咱们不确定哪条路是最佳挑选,这也是咱们鼓舞咱们在此深化探究的原因。

When can I start doing this stuff?

我什么时分能够开端着手?

This is always the next question once we explain this plan. The best answer is: probably next year, sometime. The work necessary to get npm there as a program has already started, but npm Inc's first mission has to be becoming a self-sustaining entity, which is why we're concentrating on releasing private packages first, in early 2015. After that our likely next focus will be growing the usefulness of the registry itself, and that's where client-side packaging comes in.

一旦咱们讲清楚了这个计划之后,接下来每个人都会问出这个问题。咱们只能说:可能是下一年(译注:2015 年)的某个时分。将 npm 改形成上述作用所需求的作业早已启动了,但 npm 公司的首要任务是得先让自己成为一个自给自足的实体,这也是为什么咱们会在 2015 年前期专心于发布 “私有包” 服务。在此之后,咱们的下一个专心点应该便是扩展包库房本身的功用了,到时将是客户端包处理功用的上台之时。

What can I do right now?

我现在能够做什么?

It's all well and good saying we're going to support this stuff, b哥哥我难过你帮帮我ut you have this problem right now! So what can you do immediately, starting today?

咱们将对此供给支撑,这的确没错,但这个问题现在就横在你的面前啊!那你眼下能够做些什么呢?

1. Use our registry

1. 运用咱们的包库房

There's no reason not to. It's fast, it's got 99.99% uptime, and it's free for open-source projects and always will be.

没有理由不这么做。它很快,它的可用性高达 99.99%,并且它对开源项目是(并且永久都将是)免费的。

2. Use package.json for metadata

2. 选用 package.json 作为装备文件

Again, no reason not to. It's your package, describe it how you want. Try to avoid duplicating data (don't make your own "name" field) and avoid generic names, but otherwise: have at it. If you think what you're trying to do with package.json is particularly weird or complicated, we are always available on IRC, Twitter and email if you want to run the idea past us first.

相同,没有理由不这么做。它是你的包,就用你想要的办法来描绘它吧。要注意防止数据重复(不要别的弄出一个你自己的 "name" 字段),并且防止通用的字段名,除此以外,你就放手去做吧。假如你发觉自己对 package.json 的运用办法有些奇怪或杂乱,随时能够经过 IRC、Twitter 和 Email 找到咱们——假如你想先跟咱们通个气的话。

3. Tag your packages

3. 给你的包打标签

The npm "keywords" field is somewhat under-used right now, and can be used to unambiguously claim membership or compatibility with a specific ecosystem, even before they exist. For example, I tagged a package "ecosystem:hapi" and you can search for it by that tag. This obviously isn't as good as a real ecosystem because the automatic validation isn't there, but it's better than ambiguous keywords.

现在 npm 的 "keywords" 字段在某种程度上运用得还不行,其实它能够用来明晰地声明包与某个生态圈的从属联系或兼容性,即便这个生态圈yy紫金公会还不存在也没联系。举个比如,假如我给一个包打上 “ecosystem:hapi” 的标签,那你就能够用这个标签搜到它了。这种办法显着不能像一个真实的生态圈那样好用,由于它不具有(将来生态圈功用将会供给的)主动的验证机制,但这总比模糊不清的关键字要好。

4. Use lifecycle scripts, and browserify

4. 运用生命周期脚本,以及 Browserify

It's not a perfect solution, but we think there is merit to exploring the idea of managing client-side assets installed by npm using lifecycle scripts. You could for instance have a "postinstall" script that moves packages installed by npm into a flat structure, and queries about dependency resolution. It's by no means perfect, but if you're desperate for a solution right now, we're interested to see what you can come up with using these, and your pain points will inform the work we do in getting out of your way.

运用 生命周期脚本 来处理那些经过 npm 装置的客户端资源,并不是一个完美的处理计划,但咱们以为这个方向值得探究。比方说,你能够设置一个 "postinstall" 脚本,用来把 npm 装置的包移动到一个扁平的目录结构中,并处理依靠联系。这种办法必定不行完美,但假如你把它作为救命稻草来用,咱们会乐于重视你在这条路上能走多远,而你的痛点也将为咱们接下来的举动带来启示。

We also think browserify is amazing and under-utilized, and an end-to-end solution that worked with it automatically at install time is a really, really interesting idea (check out browserify's sweet handbookfor really great docs on how to use it effectively).

咱们还以为 Browserify 是十分棒的东西,但远没有得到充分运用。假如在装置时把它作为一个端到端的处理计划来运用,将是一个十分有构思的主意。(请查阅 Browserify 的 温馨手册,那里有十分棒的文档,会告知你怎么用好它。)

Hang in there

请再坚持一下

Front-end developers want to stop using multiple package managers. Registry owners are tired of running their registries. The current support in npm for front-end packaging isn't good enough. We know, we agree, and we're committed to making things better. npm loves you, front-enders, and we care about your use cases. We build our own website using npm, and have the same pain points. So keep giving us feedback and ideas. We're working on it.

前端开发者期望不再一同运用多个包处理器。包库房的运营者们也现已厌恶。现在 npm 对前端包处理的支撑的确还不行好。咱们知道、咱们赞同、咱们承诺会让工作变得更好。前端开发者们,npm 爱你菲妞们,并且咱们关怀你们的运用场景。咱们自己也运用 npm 来构建自己的网站,咱们也有着相同的痛点。因而,请持续向咱们供给反应和主张。咱们正在为之尽力。

There will be a winner, eventually

终究,胜者必现

One final point we think it's important to make clear: we hope that a solution emerges that is so obvious and easy to use that we can "bless" it and either build it into or bundle it as part of npm. When we do that, we don't want people to think we pulled a bait-and-switch where we claimed there would be an ecosystem and instead we picked a winner (we've seen that go wrong at other companies). There is go苏文漪ing to be a winner: we just don't know what it looks like yet.

咱们的终究观念是有必要清晰一下的:咱们期望有一个处理计划能浮出水面,它是如此直观、如此易用,以致于咱们能够 “敬慕” 它,乃至把它内建到 npm 中或将它绑定为 npm 的一部分。当咱们这样做的时分,不期望人们以为咱们是在偷换概念,由于咱们曾承诺要保护一个良性的竞赛生态,但成果咱们又挑出了一位胜者(咱们知道这个做法在其它公司身上曾出过问题)。但现实上终究必将呈现一位胜者:咱们只不过是到了那个时分才知道它是谁,罢了。

If you have strong feelings about what that solution should be, building a solution that works and people use is ten thousand times more persuasive than writing a long comment on a GitHub issue about it, and also super-useful to everyone in the Node community. So go forth and build solutions, and we'll be watching closely.

假如你现已激烈地预感到那个终极计划是个什么姿态,就去完成并推行它吧,这比在 GitHub issue 里写长篇谈论要强一万倍;相同,关于每个处在 Node 社区的人来说,这也是极端受用的。因而,大步向前,去构建处理计划吧,咱们会亲近重视的!


译者跋文

开始搭档将这篇文章引荐给我时,我没有读下去。当江湖风闻 Bower “要完” 时,我再次翻出了这篇文章,并将它翻译了出来。

但译完之后,坦白地说,我有些绝望。npm 在这篇文章中并没有供给任何有用的处理计划,仅仅期望 “夸姣的工作必将发作”。这篇文章发表于 2014 年末,但直到现在 npm 也没有拿出文中说到的 “生态圈” 功用;这一年多来,前端包处理范畴也没有显现任何真命天子般的终级处理计划。

不过,在前端开发者这一端,包处理的实践风向却是发作了不小的改变。最显着的潮流便是 “抛弃 Bower,直接选用 npm”。这背面的推力,一方面是越来越多的 npm 包选用 UMD 作为发布办法,网页直接运用也无压力(当然咱们也能够以为这一点与上述潮流互为因果);另一方面jalals,前端资源的构建进程已成常态,在页面中经过

标签直接引进脚本的状况越来越少了,Bower 的独有价值也就少了许多。此外,npm3 的扁平化目录结构也进一步瓦解了前端开发者的心思防地。

如此看来,npm 动作虽慢,但斗转星移,自己却被推到浪潮之巅。这篇文章已无时效,但读起来依然很有意思,令咱们有时机一窥这家公司的思想办法与价值观。

期望本文能协助到您!

点赞+转发,让更多的人也能看到这篇内容(保藏不点赞,都是耍流氓-_-)

重视 {我},享用文章首发体会!

每周要点霸占一个前端技能难点。更多精彩前端内容私信 我 回复“教程”

原文链接:https://github.com/cssmagic/blog/issues/57

版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

沈阳,我国坚持亚太地区最大游客客源地,nbc

  • 雪花图片,北京学科类线上训练组织须月底前完结存案,贝壳

  • 卤肉的做法,欧美股市止跌回升!券商组织怎么看待节后A股行情?,chair

  • 价值观,有这个特征的人,意味着婚姻不顺,克丽缇娜