【问题标题】:npm-watch Sub Foldersnpm-watch 子文件夹
【发布时间】:2018-03-20 21:34:48
【问题描述】:

我正在使用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 来完成这个。有什么想法吗?谢谢。

【问题讨论】:

    标签: npm nodemon


    【解决方案1】:

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

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

    这种全局模式; src/**/*.js,将在src/ 目录和src/ 目录的子目录中找到所有.js 文件(很多层级)。

    【讨论】:

      猜你喜欢
      • 2020-08-10
      • 2017-11-04
      • 2017-07-07
      • 1970-01-01
      • 2016-07-09
      • 2014-11-12
      • 2017-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多