0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

npm-scripts の pre, post プレフィックス

Last updated at Posted at 2020-10-18

npm-scripts には、pre または post プレフィックスをつけることで、その npm-scripts の前後に実行される処理を記述することができます。

  • prexxxx
    • npm-scripts の xxxxに実行される
    • ex) prestartstartに実行される
  • postxxxx
    • npm-scripts の xxxxに実行される
    • ex) prestartstartに実行される
# cowsay 実行前に実行する precowsay、cowsay 実行後に実行する postcowsay を追加(内容はechoされる簡単なもの)
$ vi package.json
{
  (省略)
  "dependencies": {
    "cowsay": "^1.4.0"
  },
  "scripts": {
    "cowsay": "cowsay",
+   "precowsay": "echo 'pre cowsay'",
+   "postcowsay": "echo 'post cowsay'"
  },
  (省略)
}

# npm-scripts の cowsay コマンド実行によって package.json の npm-scripts の precowsay と postcowsay が実行されることの確認
$ npm run -s cowsay -- "hoge"
pre cowsay
 ______
< hoge >
 ------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
post cowsay
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?