How do I add a custom script to my package.json file that runs a javascript file?

前端 未结 6 887
生来不讨喜
生来不讨喜 2020-11-29 17:01

I want to be able to execute the command script1 in a project directory that will run node script1.js.

script1.js is a file in

6条回答
  •  生来不讨喜
    2020-11-29 17:28

    Custom Scripts

    npm run-script

    or

    npm run

    In your example, you would want to run npm run-script script1 or npm run script1.

    See https://docs.npmjs.com/cli/run-script

    Lifecycle Scripts

    Node also allows you to run custom scripts for certain lifecycle events, like after npm install is run. These can be found here.

    For example:

    "scripts": {
        "postinstall": "electron-rebuild",
    },
    

    This would run electron-rebuild after a npm install command.

提交回复
热议问题