简体   繁体   中英

Can I add a default script line to package.json

I'm a beginner in the field of frontend development and I'm starting to work on building small projects and assignments.

I was wondering how I could add a default script line to every package.json file I create using the npm init command. (I'm on MacOS)

I found out how to set the default author name (which created the.npmrc file in my home directory), however I can't seem to figure out to add the following as a default to all package files:

"scripts": { "start": "live-server --browser=firefox" },

It seems trivial, but as we'll be building out our set-up, there will be certain scripts defaults we'll need in every projects, such as "deploy" settings etc.

Is there an easy way to add this as a default so that this is pre-added with every npm init command?

Or: a classmate of mine created an automator workflow to set-up a new project folder including some starting files and a command that already runs the npm init on that folder. Is there a terminal command to add the above line to the scripts section of the package.json file which we could add to the automator workflow?

You can add custom scripts using the following command in the CLI:

npm set-script dev "nodemon server.js"

Result in package.json :

  "scripts": {
    "dev": "nodemon server.js"
  }

Consult the documentation here .

You can also write it in a shell script file to automate your projects.

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