[英]I am executing npm build on my react app, but is not creating with the last changes, how can I fix this? to build with last updates
[英]How can I deploy production npm build of react app to Azure App Service
我正在嘗試通過 ftp 將我的 React 應用程序的 npm 構建版本部署到 azure Web 服務。 我移動了 build 文件夾,但是當我加載應用程序的 URL 時,默認屏幕會加載Hey Node Developers!
.
我可以通過 github 和 kudu 進行部署。 但是,我認為這不是生產質量的應用程序,因為它不是使用帶有create-react-app
npm run build
。
我已經閱讀了這個 azure guide以及各種博客。 我還包含了web.config
文件。 沒有什么可以讓我的頁面正確加載。
我嘗試使用節點版本10.1
、 10.14
和LTS
。 我嘗試使用 Linux 和 Windows 應用服務。
由於 Linux Azure Web Apps 使用 pm2 為節點應用程序提供服務,因此您需要在“設置>常規設置>啟動命令”中配置Azure Linux Web 應用程序服務以運行啟動命令來為您的 React 應用程序提供服務:
pm2 serve /home/site/wwwroot/ --no-daemon
請記住更改構建路徑的路徑(您的 index.html 文件的路徑)。
如果您使用 react-router 並希望通過 index.html 處理對自定義路由的任何直接訪問,則需要在同一命令上添加--spa
選項。
pm2 serve /home/site/wwwroot/ --no-daemon --spa
使用--spa
選項--spa
將自動將所有查詢重定向到 index.html,然后反應路由器將發揮其魔力。
您可以在 pm2 文檔中找到有關它的更多信息: https ://pm2.keymetrics.io/docs/usage/pm2-doc-single-page/#serving-spa-redirect-all-to-indexhtml
我最近解決了同樣的問題: React router direct links not working on Azure Web App Linux
Deployment
> Deployment Center
打開您的應用服務 - 如果您已經設置了部署選項,則必須按Disconnect
。Local Git
> App Service Build Service
> Summary
> Finish
https://<user_name>@<app_service_name>.scm.azurewebsites.net:443/<app_service_name>.git
npm run build
./build
完成構建后運行git init
以初始化您的 git repogit remote add azure https://<user_name>@<app_service_name>.scm.azurewebsites.net:443/<app_service_name>.git
以添加 Azure 部署作為推送到的選項git add *
和git commit -m "${date}"
和git push azure master:master
https://<app_service_name.azurewebsites.net
可用如果您希望將來將更新推送到您的應用服務,您只需執行第 8 步到第 10 步。
要將react-router
與 react SPA 一起使用,您還需要配置 Web 應用程序以將 404 錯誤重新路由到index.html
。 您可以通過在/site/wwwroot/
添加一個名為web.config
。 放置以下內容並從 Azure 門戶重新啟動應用服務。
<?xml version="1.0"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="React Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.