GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Modul 5 von 9 · Text

The package.json file

Tomas Katz

Package.json

The file which defines your project. Lists all its dependencies, for both dev environment and production environment, that should be installed with npm install.

it also specifies node scripts to run in the different life cycles of the project. such scripts are:

  • install - goes over dependencies and installes them
  • preinstall - node script to run prior to running the install script.
  • postinstall - node script to run after installation of node modules finished.
  • uninstall - remove all node modules
  • preuninstall - run script before uninstall operation
  • postuninstall - run script after uninstall.

You can also define your own scripts to use with in these scripts. for example:

"build" : "node rimraf dist && webpack --config config/webpack.prod.js --progress --profile --bail",
"postinstall" : "build"

In the above example we wrote a new script called build where we first run node rimraf dist which clears the "dist" folder, then we run webpack --config config/webpack.prod.js --progress --profile --bail which runs the webpack compiler with a specified path to its config file (this process will refill the dist folder).
Then we use the new build script inside the postinstall script. this will have the effect of the project building right after the install process finishes.

devDependencies

When specifying dependencies in you package json you should do that in two properties the dependencies property and the devDependencies  property.
The devDependency object is different than the dependencies object by that that it will only install using the install command, it will not install when passing the --production flag to the install command, or when installing a package using the 
npm install "$package" command thus providing an install environment for development.

In the devDependencies object you should define test-packages for testing, transpiles for your project, development servers, and other packages you need for development purposses only.

Anleitung

Um im Kurs weiterzukommen, sende einen Versuch dieses Quiz ab. Du kannst ihn nach der letzten Frage absenden.

Zum gewählten Modul

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck