npm-watch子文件夹

时间:2018-03-19 19:20:57

标签: npm nodemon

我使用npm-watch来查看我的文件以进行更改,但它只在我的src文件夹中处理js文件,而不是在任何子文件夹中。

我的package.json:

{
  "name": "dla",
  "version": "1.0.0",
  "description": "",
  "main": "src\\index.js",
  "scripts": {
    "build": "webpack",
    "test": "echo \"Error: no test specified\" && exit 1",
    "watch": "npm-watch"
  },
  "babel": {
    "presets": [
      "env"
    ]
  },
  "watch": {
    "build": "src/*.js" <---HERE
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "css-loader": "^0.28.11",
    "jquery": "^3.3.1",
    "prop-types": "^15.6.1",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "style-loader": "^0.20.3"
  },
  "devDependencies": {
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.3",
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "npm-watch": "^0.3.0",
    "webpack": "^4.0.1",
    "webpack-cli": "^2.0.9"
  }
}

文档并没有详细说明如何执行此操作。从文档中可以看出:

This module does very little but run nodemon for you, all credit for the reliable file watching and process restarting should go to there.

所以也许我可以用nodemon完成这个。有什么想法吗?感谢。

1 个答案:

答案 0 :(得分:2)

将glob模式设置为使用双圆形星(**),如下所示:

"watch": {
  "build": "src/**/*.js"
},

这个水珠图案; src/**/*.js,将在.js目录和src/目录的子目录中找到所有src/个文件(深层次很多)。