How to run a npm script before run build in package.json ?

To run a script before run build in package.json file, you just add prebuild in script like this:

In the package.json file:

 "scripts": {
    "start": "…scripts start",
    "build": "…scripts build",
    "prebuild": "npm run dosomethings",
    "dosomethings": "node dosomethings.js",
    "…other scripts": ...
  },


Explanation: When you call build command, prebuild command will be called first, when dosomethings script is completed, build command will run.

Don't forget put your script code that you'd like to run before run build into dosomethings.js file.

© 2019 4codev

Created with love by Sil.