日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

react部署在node_如何在没有命令行的情况下在3分钟内将React + Node应用程序部署到Heroku

發布時間:2023/11/29 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 react部署在node_如何在没有命令行的情况下在3分钟内将React + Node应用程序部署到Heroku 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

react部署在node

In this tutorial we will be doing a basic React + Node app deploy to Heroku.

在本教程中,我們將進行基本的React + Node應用程序部署到Heroku。

There are a lot of tutorials that do this only using the command line, so to change things up a bit, I will do it completely without the command line.

有很多教程僅使用命令行來執行此操作,因此,要稍微改變一下內容,我將完全不用命令行來執行此操作。

For things like generating React and Express apps, we have no choice but to use the command line. For everything else we'll use a GUI.

對于生成React和Express應用程序之類的事情,我們別無選擇,只能使用命令行。 對于其他所有內容,我們將使用GUI。

I also assume you have a Github and Heroku account. They are both free, so no worries about signing up.

我還假設您有一個Github和Heroku帳戶。 它們都是免費的,因此無需擔心注冊。

sample project:https://github.com/iqbal125/react-express-sample

示例項目: https : //github.com/iqbal125/react-express-示例

React和快速設置 (React and Express Setup)

First, let's start by creating two directories named Server and Client.

首先,讓我們開始創建兩個名為ServerClient的目錄

The Client directory will hold the contents of the create-react-app command, and Server will hold the contents of the express command. This library just creates a simple Express app for us automatically, similar to create-react-app. It needs to be installed globally, which you can do so with the command:

Client目錄將保存create-react-app命令的內容,而Server將保存express命令的內容。 這個庫只是為我們自動創建一個簡單的Express應用,類似于create-react-app 。 它需要全局安裝,您可以使用以下命令進行安裝:

npm install -g express-generator

npm install -g express-generator

After this, simply run these commands in each of the respective directories to install the starter projects:

之后,只需在每個相應的目錄中運行以下命令來安裝入門項目:

npx create-react-app app1 in the Client directory

客戶端目錄中的npx create-react-app app1

express in the Server directory

express在服務器目錄

Change to the app1 directory generated by create-react-app and run:

轉到由create-react-app生成的app1目錄,然后運行:

npm run build

npm run build

This will generate a production build version of the project that is optimized for a production deployment, with things like the error handling code and white space removed. ?

這將生成該項目的生產構建版本,該版本針對生產部署進行了優化,并刪除了錯誤處理代碼和空白。

Note: In a development build you would use a proxy to http://localhost:5000 to communicate from your React app to your Express server, but here the React app and the Express server are just one project. The Express server serves the React files.

注意:在開發構建中,您將使用http:// localhost:5000的代理從您的React應用程序與Express服務器進行通信,但是在這里,React應用程序和Express服務器只是一個項目。 Express服務器提供React文件。

Next, cut and paste the entire build directory into the Server directory. Your project structure should look like this:

接下來,將整個構建目錄剪切并粘貼到Server目錄中。 您的項目結構應如下所示:

We can now add some code to let our Express server know to serve our React project.:

現在,我們可以添加一些代碼來讓Express服務器知道為我們的React項目提供服務:

....app.use(express.static(path.join(__dirname, 'build')));app.get('/*', (req, res) => {res.sendFile(path.join(__dirname, 'build', 'index.html')); });....

The first line of code serves all our static files from the build directory.

第一行代碼為構建目錄中的所有靜態文件提供服務。

The second piece of code is to keep our client side routing functional. This code essentially serves the index.html file on any unknown routes. Otherwise we would need to rewrite our entire routing to work with this Express server setup.

第二段代碼是保持我們的客戶端路由功能正常。 此代碼本質上在任何未知路由上提供index.html文件。 否則,我們將需要重寫整個路由以與此Express服務器設置一起使用。

To test your app, just run npm start in the Server directory and go to http://localhost 3000 in the browser. Then you should be see your running React app.

要測試您的應用,只需在Server目錄中運行npm start并在瀏覽器中轉到http:// localhost 3000 。 然后,您應該會看到正在運行的React應用程序。

Now we are ready to upload this project to GitHub.

現在,我們準備將這個項目上傳到GitHub。

的GitHub (GitHub )

Instead of using the command line to upload to GitHub, we will do this with the GUI. First, go to the GitHub homepage and create a new repository. Name it whatever you want, but make sure the Initialize this Repository with a README option checked:

我們將使用GUI來執行此操作,而不是使用命令行將其上傳到GitHub。 首先,轉到GitHub主頁并創建一個新的存儲庫。 將其命名為任意名稱,但請確保選中了使用README初始化此存儲庫選項:

Next upload all the project files without the node_modules directory.

接下來,上載所有沒有node_modules目錄的項目文件。

Click commit and we are done. Your uploaded project files will appear on GitHub like so:

單擊提交,我們就完成了。 您上傳的項目文件將出現在GitHub上,如下所示:

Now we can move on to setting up Heroku.

現在我們可以繼續設置Heroku。

Heroku (Heroku)

Go to the Heroku dashboard, create a new app, and name it whatever you like.

轉到Heroku儀表板,創建一個新應用,然后根據需要命名。

Next, go to the Deploy tab and select GitHub under Deployment method:

接下來,轉到Deploy選項卡,然后在Deployment method下選擇GitHub:

If you haven't connected your GitHub account to your Heroku account yet, you will be prompted through the GitHub Auth flow.

如果尚未將GitHub帳戶連接到Heroku帳戶,則將通過GitHub Auth流程提示您??。

After this, search for your project on GitHub and connect to it:

之后,在GitHub上搜索您的項目并連接到它:

Finally, we can just deploy our app by clicking the Deploy Branch button:

最后,我們可以通過單擊Deploy Branch按鈕來部署我們的應用程序:

Heroku will install all the Node modules for you automatically. You can view your project by clicking on the View button.

Heroku將自動為您安裝所有Node模塊。 您可以通過單擊查看按鈕來查看您的項目。

And that's it, we're done! Thanks for reading.

就是這樣,我們完成了! 謝謝閱讀。

Connect with me on Twitter for more updates on future tutorials: https://twitter.com/iqbal125sf

在Twitter上與我聯系以獲取未來教程的更多更新: https : //twitter.com/iqbal125sf

翻譯自: https://www.freecodecamp.org/news/deploy-a-react-node-app-to/

react部署在node

總結

以上是生活随笔為你收集整理的react部署在node_如何在没有命令行的情况下在3分钟内将React + Node应用程序部署到Heroku的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 日韩欧美在线中文字幕 | 欧美性生交xxxxx久久久 | 久操香蕉| 在线免费观看黄网站 | 国产一区二区啪啪啪 | 福利电影一区 | 免费色播 | 国产日韩欧美自拍 | jjzz黄色片| 99资源在线 | 三叶草欧洲码在线 | 少妇一级淫免费观看 | 在线看片亚洲 | 精品久久久中文字幕 | 欧美成人黄色片 | 欧美男人亚洲天堂 | 自拍三级视频 | 无人在线观看高清视频 | 熟妇高潮一区二区三区在线播放 | 国产精品111 | caoporn免费在线 | 久久久久久网址 | 日韩色吧 | a亚洲精品 | 国产浮力第一页 | 久久高清av | 99热久久这里只有精品 | 日韩少妇 | 成人免费看类便视频 | 中文字幕偷拍 | 肉性天堂 | 免费在线观看黄视频 | 91久久精品夜夜躁日日躁欧美 | 久久电影一区二区 | 国产精品500部 | 国产欧美日韩另类 | 欧美不卡影院 | 亚洲av首页在线 | 日韩一区二区三区不卡 | 99涩涩 | 欧美乱码精品一区二区 | 亚洲涩涩爱 | 婷婷色小说 | 黄色一级视频 | aaaa黄色| 奇米狠狠干 | 日韩欧美视频 | 97人妻精品一区二区三区免 | 91视频免费视频 | 自拍偷拍2019 | 国产在线黄 | 91成人小视频 | 久久ww| 男女猛烈无遮挡 | 国产精久久久久 | 日本少妇三级 | 爆乳熟妇一区二区三区霸乳 | 91麻豆精品久久久久蜜臀 | 男女国产视频 | 亚洲品质自拍视频 | 中文字幕av久久爽一区 | 青青艹视频 | 久久国产免费看 | 久久国产精品99久久人人澡 | 波多野结衣在线视频播放 | 日本极品少妇 | 国产精品香蕉国产 | 国产成人精品无码播放 | 91免费进入 | 欧美成在线视频 | 伊人视频 | 思思在线视频 | 日韩一卡二卡 | 亚洲av永久无码精品 | 久久丝袜美腿 | 亚洲一区二区三区在线看 | av私库在线观看 | 一区在线观看视频 | 国产精品无 | 欧美综合亚洲图片综合区 | 成人av免费在线 | 久久精品黄 | 国产一区二区波多野结衣 | 欧美区国产区 | 免费看欧美黄色片 | 日韩免费av一区二区 | www.99爱 | 热re99久久精品国产99热 | 国产成人精品视频一区二区 | 性欧美free| 超碰997| 在线国产91 | 日韩国产传媒 | 亚洲精品lv | www色天使 | 亚洲色图偷拍视频 | 99国产精品99久久久久久粉嫩 | 免费黄色一区二区 | 国产亚洲精品码 |