0

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 the 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. What could be the 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"
  }
}
Čamo
  • 3,863
  • 13
  • 62
  • 114

1 Answers1

0

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.

Čamo
  • 3,863
  • 13
  • 62
  • 114