Mar*_*arc 18 localhost npm reactjs server
我刚刚开始使用react.js教程,我已经下载了文件,然后提到:
"通过在浏览器中打开http:// localhost:3000来跟踪您的进度(启动服务器后)."
我知道这可能听起来很愚蠢,(因为我是React的初学者,请耐心等待)但是如何在这个实例中启动服务器?
谢谢.
渣
# install react cli
npm install -g create-react-app
# create app
create-react-app my-react-app-name
# go to project folder
cd my-react-app-name
# install dependencies
npm install
# start live server
npm start
Run Code Online (Sandbox Code Playgroud)
输出:
$ You can now view my-react-app-name in the browser.
$ Local: http://localhost:3000/
$ On Your Network: http://192.168.0.105:3000/
$ Note that the development build is not optimized.
$ To create a production build, use npm build.
Run Code Online (Sandbox Code Playgroud)
您可以运行以下任一命令来启动 ReactJS 应用程序的节点服务器:
上述所有命令都是等效的,但人们更喜欢第三个命令,因为它在键盘上输入的时间最短。
这些命令中的 start 参数映射到任何ReactJS 应用程序的 package.json 文件中脚本配置下的启动键。以下是我的 hello-world 应用程序的示例package.json文件:
{
"name": "hello-world",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2"
},
"devDependencies": {
"react-scripts": "0.9.5"
},
"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)
可以看到startreact-scripts start
键前面写着。因此,当我们运行我在开始时列出的三个命令中的任何一个时,命令将被触发,例如。react-scripts start
npm start
归档时间: |
|
查看次数: |
39154 次 |
最近记录: |