LoginSignup
8
2

More than 5 years have passed since last update.

Windows環境においてnpm-scripts経由でchokidar-cliが正常に動かない場合の対応

Last updated at Posted at 2016-12-20

地味にハマったので、メモしときます。

よくある npm script

chokidar-cli を使用して src 以下を監視し、変更があったら npm run build を実行したい、という場合

package.json
"scripts": {
    "build": "browserify -t babelify src/index.js > dist/bundle.js --debug",
    "watch": "chokidar 'src/**' -c 'npm run build'"
},

↑のようなサンプルをよく見かけますが、Windowsだと上手く動きません。
シングルクォートが無視されるようで、-c で指定したコマンドを実行してくれません。

対応策

以下のように シングルクォートの代わりにエスケープしたダブルクォートで括るようにしてください。

package.json
"scripts": {
    "build": "browserify -t babelify src/index.js > dist/bundle.js --debug",
    "watch": "chokidar \"src/**\" -c \"npm run build\""
},

chokidar に限らず、Windowsで npm-scripts を使用する場合は気をつける必要がありますね。

8
2
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
8
2