LoginSignup
277
258

More than 5 years have passed since last update.

npm-scriptsについて

Last updated at Posted at 2014-08-30

npm-scriptsについて

npmは"scripts"というフィールドにshell scriptとエイリアスコマンドを指定できる。

{
  "name": "myapp"
  "scripts": {
    "start":      "node app.js",
    "production": "NODE_ENV=production node app.js"
  }
}

npm startshell script

4

npm-scripts



start

appshell script



restart

appshell script



stop

appshell script



test

appshell script



npmnpm-scripts



publish

npm publish



install

npm install



uninstall

npm uninstall



update

npm update




npmnpm-scriptsnode_modules/.hooks/

npm-scripts


npm-scripts( : 'production')npm production

npm-scriptsnpm run-script
npm run-sctipt production

alias:

npm run production

npm-scriptsの前後に実行されるnpm-scripts


npm-scriptsnpm-scripts


pre

npm-scripts

 : prestartstart



post

npm-scripts

 : prestartstart







prepublish

npm publish



preinstall

npm install



postuninstall

npm uninstall



preupdate

npm update



npm-config


"config"app
{
  "name": "myapp"
  "scripts": {
    "start": "node app.js"
  },
  "config": {
    "port": "8080"
  }
}

ここで記述されたappの設定は、npm-scriptsで実行する時、環境変数にnpm_package_config_というプレフィックスがついて設定される。

http.createServer(function() {
  ;
}).listen(process.env.npm_package_config_port);

このnpm-configの記述は、npmコマンドを用いて行うこともできる。

npm config set myapp:port 80
277
258
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

277
258