简体   繁体   中英

npm-watch runs only once

I tried to use npm-watch as file watcher to compile scss files. As I run npm run watch the script runs and does what I expected. But after run it immediately ends and does not run again on file change. In other words it works but it does not watching. It only runs once. Can somebody tell me please what could be a problem?

This is package.json

{
  "name": "limitless",
  "version": "1.0.0",
  "main": "index.js",
  "dependencies": {
    "autoprefixer": "^10.2.5"
  },
  "devDependencies": {
    "jshint": "^2.10.3",
    "node": "14.16.0",
    "node-sass": "^5.0.0",
    "npm-watch": "^0.11.0",
    "uglify-js": "^3.16.1",
    "uglifycss": "^0.0.29"
  },
  "watch": {
    "patterns": ["www/scss"],
    "extensions": ["scss"],
    "delay": "2000"
  },
  "scripts": {
    "watch": "node-sass www/scss/theme.scss www/css/theme.css"
  }
}

Thanks for any help.

The problem was that called npm run watch insted of npm-watch. The solution looks like this:

  "watch": {
    "compile-css": {
      "patterns": ["www/scss"],
      "extensions": ["scss"],
      "delay": 250,
      "runOnChangeOnly": true
    },
    "compile-js": {
      "patterns": ["www/js/src"],
      "extensions": ["js"],
      "delay": 250,
      "runOnChangeOnly": true
    }
  },
  "scripts": {
    "compile-css": "npm run scss && npm run minify-css",
    "compile-js": "uglifyjs www/js/src/app.js -o www/js/dist/app.min.js & uglifyjs www/js/src/main.js -o www/js/dist/main.min.js",
    "scss": "node-sass www/scss/theme.scss www/css/theme.css",
    "minify-css": "css-minify -f www/css/theme.css -o www/css",
    "js": "npm run uglifyjs ",
    "watch": "npm-watch"
  },

and so I run npm run watch which calls npm-watch which triggers other scripts if files has been changed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM