admin管理员组文章数量:1357294
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. is it any default npm script mand?
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. is it any default npm script mand?
-
1
npm run start
is so mon that npm implements a shortcut to save you from typingrun
. – Nicholas Tower Commented Nov 26, 2019 at 5:25
2 Answers
Reset to default 5There a set of default built in npm scripts that can be executed without the "run"keyword.These are
install, preinstall, preuninstall, postuninstall
prepublish, prepare, prepublishOnly, prepack, postpack,
publish,preversion, version, postversion,
pretest, test, posttest: Run by the npm test mand.
prestop, stop, poststop: Run by the npm stop mand.
prestart, start, poststart: Run by the npm start mand.
prerestart, restart, postrestart: Run by the npm restart mand. Note: npm restart will run the stop and start scripts if no restart script is provided.
Some even run automatically after a given mand (postinstall - after "npm install"). To fully understand these scripts please refer documentation here
In addition to this you can also define custom scripts that can run
- any mand supported by your terminal
- any mand supported by npm.
These user defined custom scripts should be executed using "npm run ... ".
The instructions that need to run on these scripts are defined under the scripts section of the package.json file. In the package.json shown below "start" and "test" are inbuilt, npm recognizable, mands. "build", "myinit", "deletefolder", "hellovnoitkumar" are custom scripts that are custom defined.
The supported npm executions for this package.json are
- npm start (inbuilt)
- npm test (inbuilt)
- npm run build (custom)
- npm run myinit (custom)
- npm run deletefolder (custom)
- npm run hellovnoitkumar (custom)
Sample 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 mand 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 mands, 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. You can also use built-in scripts with "run", it will be pretty equal.
本文标签: javascriptHow npm start worksit should be npm run start (Create React App)Stack Overflow
版权声明:本文标题:javascript - How npm start works, it should be npm run start? (Create React App) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744075830a2586726.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论