[英]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.