Movatterモバイル変換


[0]ホーム

URL:


Skip to searchSkip to content

Site navigation

Specifying dependencies and devDependencies in a package.json file

To specify the packages your project depends on, you must list them as"dependencies" or"devDependencies" in your package'spackage.json file. When you (or another user) runnpm install, npm will download dependencies and devDependencies that are listed inpackage.json that meet thesemantic version requirements listed for each. To see which versions of a package will be installed, use thesemver calculator.

  • "dependencies": Packages required by your application in production.
  • "devDependencies": Packages that are only needed for local development and testing.

Adding dependencies to apackage.json file

You can add dependencies to apackage.json file from the command line or by manually editing thepackage.json file.

Adding dependencies to apackage.json file from the command line

To add dependencies and devDependencies to apackage.json file from the command line, you can install them in the root directory of your package using the--save-prod flag (also-S) for dependencies (the default behavior ofnpm install) or the--save-dev flag (also-D) for devDependencies.

To add an entry to the"dependencies" attribute of apackage.json file, on the command line, run the following command:

npm install <package-name> [--save-prod]

To add an entry to the"devDependencies" attribute of apackage.json file, on the command line, run the following command:

npm install <package-name> --save-dev

Manually editing thepackage.json file

To add dependencies to apackage.json file, in a text editor, add an attribute called"dependencies" that references the name andsemantic version of each dependency:

{
"name":"my_package",
"version":"1.0.0",
"dependencies":{
"my_dep":"^1.0.0",
"another_dep":"~2.2.0"
}
}

To add devDependencies to apackage.json file, in a text editor, add an attribute called"devDependencies" that references the name andsemantic version of each devDependency:

"name":"my_package",
"version":"1.0.0",
"dependencies":{
"my_dep":"^1.0.0",
"another_dep":"~2.2.0"
},
"devDependencies":{
"my_test_framework":"^3.1.0",
"another_dev_dep":"1.0.0 - 1.2.0"
}
Edit this page on GitHub
5 contributorsshallow-beachlukekarrysservel333drylintethomson
Last edited byshallow-beach onAugust 8, 2024

[8]ページ先頭

©2009-2025 Movatter.jp