"react-scripts start"命令究竟是什么? [英] What exactly is the 'react-scripts start' command?

查看:1507
本文介绍了"react-scripts start"命令究竟是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用create-react-app处理一个React项目,并且有两个选项可以启动该项目:

I've been working with a React project, using create-react-app, and I have two options to start the project:

第一种方式:

npm run start,其定义在package.json处,如下所示:

npm run start with the definition at the package.json like this:

"start": "react-scripts start",

第二种方式:

npm start

这两个命令有什么区别? react-scripts start的目的是什么?

What is the difference between these two commands? And what is the purpose of the react-scripts start?

我试图找到定义,但我只是找到了一个带有名称的包,但我仍然不知道该命令的含义.

I tried to found the definition, but I just found a package with the name, and I still don't know what is the meaning of this command.

推荐答案

create-react-app和react-scripts

react-scripts create-react-app 入门包中的一组脚本. create-react-app可帮助您启动项目而无需进行配置,因此您不必自己设置项目.

create-react-app and react-scripts

react-scripts is a set of scripts from the create-react-app starter pack. create-react-app helps you kick off projects without configuring, so you do not have to setup your project by yourself.

react-scripts start设置开发环境并启动服务器,以及热模块重新加载.您可以在此处阅读,以了解它为您所做的一切.

react-scripts start sets up the development environment and starts a server, as well as hot module reloading. You can read here to see what everything it does for you.

使用 create-react-app ,您可以立即使用以下功能.

with create-react-app you have following features out of the box.

  • React,JSX,ES6和Flow语法支持.
  • ES6以外的语言额外功能,例如对象传播运算符.
  • 自动前缀CSS,因此您不需要-webkit-或其他前缀.
  • 快速的交互式单元测试运行程序,内置对覆盖率报告的支持.
  • 用于警告常见错误的实时开发服务器.
  • 一个构建脚本,用于将JS,CSS和图像与哈希值和源映射捆绑在一起以进行生产.
  • 脱机优先服务工作者和Web应用程序清单,符合所有Progressive Web App标准.
  • 具有单个依赖项的上述工具的无障碍更新.
  • React, JSX, ES6, and Flow syntax support.
  • Language extras beyond ES6 like the object spread operator.
  • Autoprefixed CSS, so you don’t need -webkit- or other prefixes.
  • A fast interactive unit test runner with built-in support for coverage reporting.
  • A live development server that warns about common mistakes.
  • A build script to bundle JS, CSS, and images for production, with hashes and sourcemaps.
  • An offline-first service worker and a web app manifest, meeting all the Progressive Web App criteria.
  • Hassle-free updates for the above tools with a single dependency.

npm脚本

npm start npm run start的快捷方式.

npm scripts

npm start is a shortcut for npm run start.

npm run 用于运行您在scripts中定义的脚本您package.json的对象

npm run is used to run scripts that you define in the scripts object of your package.json

如果脚本对象中没有start键,则默认为node server.js

if there is no start key in the scripts object, it will default to node server.js

有时候您想要做的比React脚本所能提供的更多,在这种情况下,您可以做react-scripts eject.这样会将您的项目从托管"状态转换为非托管状态,您可以在其中完全控制依赖项,构建脚本和其他配置.

Sometimes you want to do more than the react scripts gives you, in this case you can do react-scripts eject. This will transform your project from a "managed" state into a not managed state, where you have full control over dependencies, build scripts and other configurations.

这篇关于"react-scripts start"命令究竟是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆