npm start和npm run start之间的区别

DIL*_*MAS 54 npm

我检查了两个命令npm startnpm run start,两者完美的作品.我使用了create-react-app.但是为了在CSS模块中进行配置更改,我运行npm eject但是它会引发错误.

npm run eject有效吗?我很困惑,为什么npm eject不工作.我可以配置吗?

以下是我的package.json:

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
Run Code Online (Sandbox Code Playgroud)

AKX*_*AKX 115

npm test,npm start,npm restart,和npm stop都是别名npm run ....

对于scripts您定义的所有其他内容,您需要使用npm run ...语法.

有关更多信息,请参阅https://docs.npmjs.com/cli/run-script上的文档.

  • 使用别名我的意思是`npm test`完全执行`npm run test`,`npm start`完全执行`npm run start`的操作,依此类推. (14认同)
  • @ user1912383您必须询问npm的作者。我想`npm start`经常被使用来保证别名。 (6认同)
  • @hashlash 对于“npm run *”也是如此。`npm run foo` 将运行 `prefoo`、`foo`、`postfoo`。 (6认同)
  • 为什么开始是别名而构建不是? (4认同)

Vim*_*ran 18

需要注意的一件有趣的事情是,
如果scripts对象在文件中没有属性,或者从命令行将默认运行。"start"package.jsonnpm startnpm run startnode server.js

但是如果scriptspackage.json中的对象有"start"属性,它会覆盖node server.js并执行属性中的命令"start"

请参阅 - https://docs.npmjs.com/cli/v7/commands/npm-start#description


Ayu*_*ain 14

npm start是 的缩写形式npm run start。所以,它是一回事。