【问题标题】:Difference between npm start and npm run startnpm start 和 npm run start 的区别
【发布时间】:2018-12-23 18:56:46
【问题描述】:

我已经检查了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"
  }

【问题讨论】:

    标签: npm


    【解决方案1】:

    npm testnpm startnpm restartnpm stop都是npm run xxx.的别名

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

    有关详细信息,请参阅https://docs.npmjs.com/cli/run-script 的文档。

    【讨论】:

    • 好像我是新手,我没有清楚地理解那个
    • 对于别名,我的意思是 npm test 完全符合 npm run test 所做的,npm start 完全符合 npm run start 所做的,等等。
    • 为什么 start 是别名而 build 不是?
    • @user1912383 你得问问 npm 的作者。我想npm start 经常被使用来保证别名。
    • @hashlash npm run * 也是如此。 npm run foo 将运行 prefoofoopostfoo
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      需要注意的一件有趣的事情是,
      如果scripts 对象没有package.json 文件中具有"start" 属性,则命令行中的npm startnpm run start 将默认运行node server.js

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

      见 - https://docs.npmjs.com/cli/v7/commands/npm-start#description

      【讨论】:

        猜你喜欢
        • 2019-04-11
        • 2021-11-22
        • 1970-01-01
        • 2017-03-29
        • 1970-01-01
        • 2023-04-03
        • 2021-02-01
        • 2017-10-05
        • 2018-07-16
        相关资源
        最近更新 更多