[SOLVED] Package.json scripts


#1

Hello everyone,

I was wondering what stage should I use if I want a script to be executed every time I change a file.

I’m currently using “prepublish” but the script is only executed when I modify the content of package.json.

I tried to use “prestart” but the script is not running.

Thanks !


#2

Hi Sladix, these are the current rules:

changes to package.json and .env trigger an npm install (and also the preinstall and postinstall scripts).

changes to *.js and *.coffee files outside of public/ and dist/ folders trigger npm start (but not the pre/post start scripts).

changes to other files trigger a simple refresh of the preview window (if open and enabled).

Which part of this doesn’t work for you? A simple workaround to trigger the prestart script is to add it to your start script:

package.json:

...
"scripts": {
  "prestart": "do something",
  "start": "npm run prestart && your start command"
},
...

#3

Thanks for your clear response !

I wasn’t aware of the command1 && command2 syntax (I’m quite new on node and cli commands in general).

So my work around is simply to set both of my commands in the start script.

I hope your answer will help other people too !