[英]How npm start works, it should be npm run start? (Create React App)
In Create React App we start our app with npm start
but for the build, we use npm run build
it should be npm run start
but how npm start
works.在 Create React App 中,我们使用
npm start
启动我们的应用程序,但对于构建,我们使用npm run build
它应该是npm run start
但npm start
是如何工作的。 is it any default npm script command?它是任何默认的 npm 脚本命令吗?
There a set of default built in npm scripts that can be executed without the "run"keyword.These are
有一组默认内置的 npm 脚本,无需“运行”关键字即可执行。这些是
install, preinstall, preuninstall, postuninstall
prepublish, prepare, prepublishOnly, prepack, postpack,
publish,preversion, version, postversion,
pretest, test, posttest: Run by the npm test command.
prestop, stop, poststop: Run by the npm stop command.
prestart, start, poststart: Run by the npm start command.
prerestart, restart, postrestart: Run by the npm restart command. Note: npm restart will run the stop and start scripts if no restart script is provided.
Some even run automatically after a given command (postinstall - after "npm install") .有些甚至在给定命令后自动运行(安装后 - 在“npm install”之后) 。 To fully understand these scripts please refer documentation here
要完全理解这些脚本,请参阅此处的文档
In addition to this you can also define custom scripts that can run除此之外,您还可以定义可以运行的自定义脚本
These user defined custom scripts should be executed using "npm run... ".
这些用户定义的自定义脚本应该使用“npm run...”来执行。
The instructions that need to run on these scripts are defined under the scripts section of the package.json file.需要在这些脚本上运行的指令在 package.json 文件的脚本部分下定义。 In the package.json shown below "start" and "test" are inbuilt, npm recognizable, commands.
在下面显示的 package.json 中,“start”和“test”是内置的、npm 可识别的命令。 "build", "myinit", "deletefolder", "hellovnoitkumar" are custom scripts that are custom defined.
“build”、“myinit”、“deletefolder”、“hellovnoitkumar”是自定义的自定义脚本。
The supported npm executions for this package.json are此 package.json 支持的 npm 执行是
Sample package.json示例 package.json
//npm start, npm test
//npm run build, npm run myinit, npm run deletefolder, npm run hellovnoitkumar
//*Note that you also can define what each built in npm command does (npm start, npm test).*
{
"name": "my-webapp",
"version": "0.1.0",
"private": true,
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-scripts": "^2.1.5",
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"myinit" : "npm install && npm run build && npm start",
"deletefolder": "rm -rf documents",
"hellovnoitkumar": "echo "hello vnoit kumar""
}
}
npm has number of built-in commands, which you can run without "run" word, like start, test, publish etc. User defined scripts, on the other hand, need to be used with "run" word. npm 有许多内置命令,您可以在没有“运行”字样的情况下运行,例如启动、测试、发布等。另一方面,用户定义的脚本需要与“运行”字样一起使用。 You can also use built-in scripts with "run", it will be pretty equal.
您也可以将内置脚本与“运行”一起使用,这将是相当平等的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.