简体   繁体   English

我可以向 package.json 添加默认脚本行吗

[英]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.我想知道如何为我使用 npm init 命令创建的每个 package.json 文件添加默认脚本行。 (I'm on MacOS) (我在 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:我发现了如何设置默认作者姓名(它在我的主目录中创建了 .npmrc 文件),但是我似乎无法弄清楚将以下内容作为默认值添加到所有 package 文件中:

"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?有没有一种简单的方法可以将其添加为默认值,以便在每个 npm 初始化命令中预先添加?

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.或者:我的一个同学创建了一个自动化工作流程来设置一个新的项目文件夹,其中包括一些启动文件和一个已经在该文件夹上运行 npm 初始化的命令。 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?是否有终端命令将上述行添加到 package.json 文件的脚本部分,我们可以将其添加到自动化工作流程中?

You can add custom scripts using the following command in the CLI:您可以在 CLI 中使用以下命令添加自定义脚本:

npm set-script dev "nodemon server.js"

Result in package.json :结果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.您还可以将其写入 shell 脚本文件以自动化您的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在package.json中的脚本中添加时间戳? - How can I add a timestamp into a script in package.json? 如何通过 package.json 脚本使用默认程序打开文件 - How can I open a file with it's default program via a package.json script 我可以从 package.json bin 脚本运行命令吗? - Can I run a command from package.json bin script? 如何在 package.json 中添加新脚本 - How to add a new script in package.json 我可以重命名 package.json 文件吗? - Can I rename the package.json file? 为什么我不能在不调用脚本的情况下运行与我的 package.json 脚本相同的命令? - Why I can't run the same command that is my script of package.json without calling the script? 如何向运行 javascript 文件的 package.json 文件添加自定义脚本? - How do I add a custom script to my package.json file that runs a javascript file? 如何设置 package.json 反应组件库的默认条目 - How can i set default entry for package.json react components library NPM安装->但仅将适当的行添加到package.json - NPM install -> but only add appropriate line to package.json 为什么我需要在 package.json 上有一个构建脚本才能在 Now 上部署一些东西? 我该如何解决? - Why I need to have an build script on package.json to deploy something on Now? and How can I fix it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM