我正在尝试将 Github Actions 与 Azure Static Web App 一起使用来部署 Web 应用程序。我在 React 应用程序中使用节点版本 20.18.0 和 .NET 8,并使用在 Visual Studio 中创建项目时提供的默认 vite 配置,并对我的项目进行了一些更改。
项目不断失败——以下是当前的工作流程文件配置:
jobs:
build_and_deploy_job:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: ubuntu-latest
name: Build and Deploy Job
steps:
- uses: actions/checkout@v3
with:
submodules: true
lfs: false
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.402
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20.18.0
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_GREEN_MUSHROOM_0A9558C1E }}
repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
action: "upload"
###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
app_location: "./mksite.client" # App source code path
api_location: "./mksite.Server" # Api source code path - optional
output_location: "dist" # Built app content directory - optional
###### End of Repository/Build Configurations ######
这是vite.config.ts文件:
const target = env.ASPNETCORE_HTTPS_PORT ? `https://localhost:${env.ASPNETCORE_HTTPS_PORT}` :
env.ASPNETCORE_URLS ? env.ASPNETCORE_URLS.split(';')[0] : 'https://localhost:7012';
export default defineConfig({
build: {
watch: null
},
plugins: [plugin(), basicSsl()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
server: {
proxy: {
'^/experience':{
target,
secure: false
},
'^/about':{
target,
secure: false
}
},
port: 5173
}
})
.esproj 文件:
<Project Sdk="Microsoft.VisualStudio.JavaScript.Sdk/1.0.1184077">
<PropertyGroup>
<StartupCommand>npm run dev</StartupCommand>
<JavaScriptTestRoot>src\</JavaScriptTestRoot>
<JavaScriptTestFramework>Jest</JavaScriptTestFramework>
<!-- Allows the build (or compile) script located on package.json to run on Build -->
<ShouldRunBuildScript>false</ShouldRunBuildScript>
<!-- Folder where production build objects will be placed -->
<BuildOutputFolder>$(MSBuildProjectDirectory)\dist</BuildOutputFolder>
</PropertyGroup>
</Project>
最后是安装 dotnet 并从服务器运行应用程序后发生的错误:
它说找不到 npm run build 命令,这不是我在本地或使用 Docker 在虚拟机上运行应用程序时看到的问题。当我在运行服务器时安装了错误版本的节点时,我确实看到了类似的情况,但我对 Azure 的了解不够,无法进行故障排除。
有什么建议吗?
完整的 ReactJs 教程在这里查看 https://youtu.be/ndcENsaE8l0