Javascript 节点更新特定包
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43127863/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Node update a specific package
提问by Samuel
I want to update my Browser-sync without updating all my node packages. How can I achieve this? My current version of Browser-sync does not have the Browser-sync GUI :(
我想更新我的浏览器同步而不更新我的所有节点包。我怎样才能做到这一点?我当前版本的浏览器同步没有浏览器同步 GUI :(
├─┬ [email protected]
│ ├── [email protected]
回答by Ryan Wheale
Most of the time you can just npm update(or yarn upgrade) a module to get the latest non breaking changes (respecting the semver specified in your package.json)(<-- read that last part again).
大多数情况下,您只需npm update(或yarn upgrade)一个模块即可获取最新的非破坏性更改(尊重 package.json 中指定的 semver)(<--再次阅读最后一部分)。
npm update browser-sync
-------
yarn upgrade browser-sync
- Use
npm|yarn outdatedto see which modules have newer versions- Use
npm update|yarn upgrade(without a package name) to update all modules- Include
--save-dev|--devif you want to save the newer version numbers to your package.json. (NOTE: as of npm v5.0 this is only necessary fordevDependencies).
- 用
npm|yarn outdated看哪个模块有新版本- 使用
npm update|yarn upgrade(不带包名)更新所有模块- 包括
--save-dev|--dev如果你想更新的版本号保存到您的package.json。 (注意:从 npm v5.0 开始,这仅适用于devDependencies)。
Major version upgrades:
主要版本升级:
In your case, it looks like you want the next major version (v2.x.x), which is likely to have breaking changes and you will need to update your app to accommodate those changes. You can install/save the latest 2.x.xby doing:
在您的情况下,您似乎想要下一个主要版本 (v2.xx),该版本可能会有重大更改,您需要更新您的应用程序以适应这些更改。您可以2.x.x通过执行以下操作来安装/保存最新版本:
npm install browser-sync@2 --save-dev
-------
yarn add browser-sync@2 --dev
...or the latest 2.1.xby doing:
...或最新2.1.x的:
npm install [email protected] --save-dev
-------
yarn add [email protected] --dev
...or the latest and greatestby doing:
...或通过以下方式获得最新最好的:
npm install browser-sync@latest --save-dev
-------
yarn add browser-sync@latest --dev
Note:the last one is no different than doing this:
npm uninstall browser-sync --save-dev npm install browser-sync --save-dev ------- yarn remove browser-sync --dev yarn add browser-sync --devThe
--save-devpart is important. This will uninstall it, remove the value from your package.json, and then reinstall the latest version and save the new value to your package.json.
注意:最后一个与这样做没有什么不同:
npm uninstall browser-sync --save-dev npm install browser-sync --save-dev ------- yarn remove browser-sync --dev yarn add browser-sync --dev该
--save-dev部分是很重要的。这将卸载它,从您的 package.json 中删除该值,然后重新安装最新版本并将新值保存到您的 package.json。
回答by Aminadav Glickshtein
Always you can do it manually. Those are the steps:
您始终可以手动完成。这些是步骤:
- Go to the NPM package page, and search for the GitHub link.
- Now download the latest version using GitHub download link, or by clonning.
git clone github_url - Copy the package to your
node_modulesfolder for e.g.node_modules/browser-sync
- 转到 NPM 包页面,并搜索 GitHub 链接。
- 现在使用 GitHub 下载链接或通过克隆下载最新版本。
git clone github_url - 将包复制到您的
node_modules文件夹中,例如node_modules/browser-sync
Now it should work for you. To be sure it will not break in the future when you do npm i, continue the upcoming two steps:
现在它应该适合你。为确保将来您这样做时它不会中断npm i,请继续接下来的两个步骤:
- Check the version of the new package by reading the
package.jsonfile in it's folder. - Open your project
package.jsonand set the same version for where it's appear in thedependenciespart of yourpackage.json
- 通过读取
package.json文件夹中的文件来检查新包的版本。 - 打开您的项目
package.json并为它出现在dependencies您的部分中的位置设置相同的版本package.json
While it's not recommened to do it manually. Sometimes it's good to understand how things are working under the hood, to be able to fix things. I found myself doing it from time to time.
虽然不建议手动进行。有时,了解事物的内部运作方式是很好的,以便能够解决问题。我发现自己不时这样做。

