You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

install.md 7.2 kB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. ---
  2. id: docs_cli_install
  3. guide: docs_cli
  4. layout: guide
  5. ---
  6. {% include vars.html %}
  7. `yarn install` is used to install all dependencies for a project. This is most
  8. commonly used when you have just checked out code for a project, or when
  9. another developer on the project has added a new dependency that you need to
  10. pick up.
  11. If you are used to using npm you might be expecting to use `--save` or
  12. `--save-dev`. These have been replaced by `yarn add` and `yarn add --dev`. For
  13. more information, see
  14. [the `yarn add` documentation]({{url_base}}/docs/cli/add).
  15. Running `yarn` with no command will run `yarn install`, passing through any provided flags.
  16. If you need reproducible dependencies, which is usually the case with the continuous integration systems, you should pass `--frozen-lockfile` flag.
  17. ##### `yarn install` <a class="toc" id="toc-yarn-install" href="#toc-yarn-install"></a>
  18. Install all the dependencies listed within `package.json` in the local
  19. `node_modules` folder.
  20. The `yarn.lock` file is utilized as follows:
  21. - If `yarn.lock` is present and is enough to satisfy all the dependencies listed in `package.json`, the exact versions recorded in `yarn.lock` are installed, and `yarn.lock` will be unchanged. Yarn will not check for newer versions.
  22. - If `yarn.lock` is absent, or is _not_ enough to satisfy all the dependencies listed in `package.json` (for example, if you manually add a dependency to `package.json`), Yarn looks for the newest versions available that satisfy the constraints in `package.json`. The results are written to `yarn.lock`.
  23. If you want to ensure `yarn.lock` is not updated, use `--frozen-lockfile`.
  24. ##### `yarn install --check-files` <a class="toc" id="toc-yarn-install-check-files" href="#toc-yarn-install-check-files"></a>
  25. Verifies that already installed files in `node_modules` did not get removed.
  26. ##### `yarn install --flat` <a class="toc" id="toc-yarn-install-flat" href="#toc-yarn-install-flat"></a>
  27. Install all the dependencies, but only allow one version for each package. On the first run this will prompt you to
  28. choose a single version for each package that is depended on at multiple
  29. version ranges. These will be added to your `package.json` under a
  30. `resolutions` field.
  31. ```json
  32. "resolutions": {
  33. "package-a": "2.0.0",
  34. "package-b": "5.0.0",
  35. "package-c": "1.5.2"
  36. }
  37. ```
  38. ##### `yarn install --force` <a class="toc" id="toc-yarn-install-force" href="#toc-yarn-install-force"></a>
  39. This refetches all packages, even ones that were previously installed.
  40. ##### `yarn install --har` <a class="toc" id="toc-yarn-install-har" href="#toc-yarn-install-har"></a>
  41. Outputs an [HTTP archive](https://en.wikipedia.org/wiki/.har) from all the
  42. network requests performed during the installation. HAR files are commonly used
  43. to investigate network performance, and can be analyzed with tools such as
  44. [Google's HAR Analyzer](https://toolbox.googleapps.com/apps/har_analyzer/) or
  45. [HAR Viewer](http://www.softwareishard.com/blog/har-viewer/).
  46. ##### `yarn install --ignore-scripts` <a class="toc" id="toc-yarn-install-ignore-scripts" href="#toc-yarn-install-ignore-scripts"></a>
  47. Do not execute any scripts defined in the project package.json and its dependencies.
  48. ##### `yarn install --modules-folder <path>` <a class="toc" id="toc-yarn-install-modules-folder" href="#toc-yarn-install-modules-folder"></a>
  49. Specifies an alternate location for the `node_modules` directory, instead of the default `./node_modules`.
  50. ##### `yarn install --no-lockfile` <a class="toc" id="toc-yarn-install-no-lockfile" href="#toc-yarn-install-no-lockfile"></a>
  51. Don't read or generate a `yarn.lock` lockfile.
  52. ##### `yarn install --production[=true|false]` <a class="toc" id="toc-yarn-install-production-true-false" href="#toc-yarn-install-production-true-false"></a>
  53. Yarn will not install any package listed in `devDependencies` if the `NODE_ENV` environment variable is set to `production`. Use this flag to instruct Yarn to ignore `NODE_ENV` and take its production-or-not status from this flag instead.
  54. > **Notes:** `--production` is the same as `--production=true`. `--prod` is an alias of `--production`.
  55. ##### `yarn install --pure-lockfile` <a class="toc" id="toc-yarn-install-pure-lockfile" href="#toc-yarn-install-pure-lockfile"></a>
  56. Don't generate a `yarn.lock` lockfile.
  57. ##### `yarn install --focus` <a class="toc" id="toc-yarn-install-focus" href="#toc-yarn-install-focus"></a>
  58. Shallowly installs a package's sibling workspace dependencies underneath its `node_modules` folder. This allows you to run that workspace without building the other workspaces it depends on.
  59. Must be run inside an individual workspace in a workspaces project. Can not be run in a non-workspaces project or at the root of a workspaces project.
  60. [Learn more about focused workspaces.](https://yarnpkg.com/blog/2018/05/18/focused-workspaces/)
  61. ##### `yarn install --frozen-lockfile` <a class="toc" id="toc-yarn-install-frozen-lockfile" href="#toc-yarn-install-frozen-lockfile"></a>
  62. Don't generate a `yarn.lock` lockfile and fail if an update is needed.
  63. ##### `yarn install --silent` <a class="toc" id="toc-yarn-install-silent" href="#toc-yarn-install-silent"></a>
  64. Run yarn install without printing installation log.
  65. ##### `yarn install --ignore-engines` <a class="toc" id="toc-yarn-install-ignore-engines" href="#toc-yarn-install-ignore-engines"></a>
  66. Ignore engines check.
  67. ##### `yarn install --ignore-optional` <a class="toc" id="toc-yarn-install-ignore-optional" href="#toc-yarn-install-ignore-optional"></a>
  68. Don't install optional dependencies.
  69. ##### `yarn install --offline` <a class="toc" id="toc-yarn-install-offline" href="#toc-yarn-install-offline"></a>
  70. Run yarn install in offline mode.
  71. ##### `yarn install --non-interactive` <a class="toc" id="toc-yarn-install-non-interactive" href="#toc-yarn-install-non-interactive"></a>
  72. Disable interactive prompts, like when there's an invalid version of a dependency.
  73. ##### `yarn install --update-checksums` <a class="toc" id="toc-yarn-install-update-checksums" href="#toc-yarn-install-update-checksums"></a>
  74. Update checksums in the `yarn.lock` lockfile if there's a mismatch between them and their package's checksum.
  75. ##### `yarn install --audit` <a class="toc" id="toc-yarn-install-audit" href="#toc-yarn-install-audit"></a>
  76. Checks for known security issues with the installed packages. A count of found issues will be added to the output. Use the `yarn audit` command for additional details. Unlike npm, which automatically runs an audit on every install, yarn will only do so when requested. (This may change in a later update as the feature is proven to be stable.)
  77. ##### `yarn install --no-bin-links` <a class="toc" id="toc-yarn-install-no-bin-links" href="#toc-yarn-install-no-bin-links"></a>
  78. Prevent yarn from creating symlinks for any binaries the package might contain.
  79. ##### `yarn install --link-duplicates` <a class="toc" id="toc-yarn-install-link-duplicates" href="#toc-yarn-install-link-duplicates"></a>
  80. Create hardlinks to the repeated modules in node_modules.
  81. ##### `yarn install --verbose` <a class="toc" id="toc-yarn-install-verbose" href="#toc-yarn-install-verbose"></a>
  82. Show additional logs while installing dependencies

js yarn包管理组件依赖分析

Contributors (1)