1dr-build-utilities 中文文档教程
Build Utilities for One Darnley Road
除了我们,它可能对任何人都没有多大用处! 在大多数情况下,我们习惯于以某种方式做事 我们的项目,所以这是一种干燥我们的 gulpfiles 的方法,并允许旧项目从中受益 更新的改进。
这也是一种重用小前端组件(主要是 JS)的方法,再次以我们一直做的方式做事。 希望我们的项目开始更多地关注这里的功能配置。
Installation
As a contributor to this repo
您可以使用 NPM 链接:
在开发过程中,假设您有访问权限,您将希望向此存储库添加内容,从而向包添加内容。 一种方法是添加代码、提交、推送、npm 发布,然后必须在活动项目中进行 npm 更新。 这有点麻烦,可能会妨碍在项目中开发文件。
为了解决这个问题,我们可以使用 npm 链接到 git 仓库。
步骤是这样的:
首先克隆这个模块的存储库(在你的主项目以外的地方),然后 进入它。 然后将其设置为 npm 以链接到其他地方。
- Clone the repo and move into that folder
$ git clone https://github.com/onedarnleyroad/build-utilities && cd build-utilities
- Install dependencies. This is important as the tools rely on various gulp plugins and so on, but because this will be symlinked, the project will not be able to find them.
$ npm install
最后链接包:
$ npm link
最后一个命令会将其设置为 NPM 的全局可用符号链接。 或者其他的东西。 我仍然是 R-ing-TFM
下一步是将此模块链接到您当前的项目中:
$ cd /my/project
$ npm install --save-dev 1dr-build-utitilies // this is kinda optional
$ npm link 1dr-build-utilities
实际上就是这样,这些实用程序现在可以在 repo 中使用。 第二次安装是可选的,因为这意味着如果其他人正在处理 /my/project
存储库,但您不希望他们有权编辑 1dr-build-utilities
然后您将这个包保存到 package.json
并且其他开发人员仍然可以使用这些工具。 但请记住,他们编译的内容和您编译的内容可能存在差异。 但对于我们自己的用例,这可能不是真实场景。
**注意:您必须在 npm 链接
之前 npm install
,这样链接就会“覆盖”从 npm 下载的包。 如果它已经是 linke 那么 npm install
将不会覆盖它。 但是,如果您在 npm link 1dr-build-utilities
之后运行 npm install 1dr-build-utilities
,这将删除链接,并安装 NPM 上托管的任何内容。
进一步阅读:http://justjs.com/posts/npm-link-developing-your-own-npm-modules-without-tears 上面的内容很有用,因为它解释了如何绕过必须键入 sudo
才能使链接正常工作,以及此方法的作用。
Simple installation
如果你只是使用这个 repo,但从未对其进行更改(也许你不是 1DR),或者你很乐意在这个上 npm publish
每当你有新文件要添加或更改时,你就可以安装传统方式:
$ npm install --save-dev 1dr-build-utilities
它只是一个模块,就像任何其他模块一样,但是由于这组实用程序将包含最有可能使用 gulp 编译的前端资产,如果人们有不同版本的模块,那么生成的包可能有过时的或行为不同的代码,并且对于生产代码来说可能有点混乱。 这可能只是要付出的代价,但也可以使用 package.json(假设您没有 npm 链接)来控制包版本。
Usage
待定……
Build Utilities for One Darnley Road
It's probably not of much use to anyone but us! We're used to doing things in a certain way in most of our projects, so this is a way to DRY out our gulpfiles, and allow older projects to benefit from improvements made in newer ones.
It's also a way to reuse little front end components (mostly JS) again doing things in the same way we always do. Hopefully our projects start to become a bit more about configuration of functionality that lives here.
Installation
As a contributor to this repo
You can use NPM link:
As you develop, assuming you have access, you'll want to add things to this repo and thus the package. One way would be to add code, commit, push, npm publish, and then have to npm update in the active project. It's a bit of a faff that might get in the way of developing files in the project.
To get around this, we can use npm link to the git repo.
The steps go like this:
First clone the repository of this module (somewhere other than your main project), and cd into it. Then set it up as an npm to be linked elsewhere.
- Clone the repo and move into that folder
$ git clone https://github.com/onedarnleyroad/build-utilities && cd build-utilities
- Install dependencies. This is important as the tools rely on various gulp plugins and so on, but because this will be symlinked, the project will not be able to find them.
$ npm install
Finally link the package:
$ npm link
The last command will set it up as a globally available symlink to NPM. Or something. I'm still R-ing-TFM
The next step is to link this module in your current project(s):
$ cd /my/project
$ npm install --save-dev 1dr-build-utitilies // this is kinda optional
$ npm link 1dr-build-utilities
That's actually it, the utilities are now available in the repo. The second install is optional as it means that if someone else is working on the /my/project
repo, but you do not want them to have access to edit 1dr-build-utilities
then you are saving this package to package.json
and other developers can still use the tools. But bear in mind there may be a discrepancy in what they compile and what you compile. But for our own use case, this is probably not a real scenario.
**NB: You must npm install
before the npm link
, so that the link 'overwrites' the package downloaded from npm. If it's already linke then npm install
will not overwrite it. However, if you run npm install 1dr-build-utilities
after the npm link 1dr-build-utilities
this will remove the link, and install whatever is hosted on NPM.
Further reading: http://justjs.com/posts/npm-link-developing-your-own-npm-modules-without-tears The above is useful because it explains getting around having to type sudo
to make the link work, and what's going on with this method.
Simple installation
If you're just using this repo, but not ever making changes to it (perhaps you aren't 1DR), or you're happy to just npm publish
on this repo whenever you've got new files to add or change then you can install the traditional way:
$ npm install --save-dev 1dr-build-utilities
It's just a module like any other, but since this set of utilities will contain front end assets that are most likely going to be compiled with gulp, if people have different versions of the modules, then the resulting bundles may have outdated or differently-behaving code, and it could be a bit of a mess for production code. That may just be the price to pay, but it's also possible to use package.json (assuming you're not npm linking) to control the package version.
Usage
TBC…