SWA-CLIhttps://azure.github.io/static-web-apps-cli/
我使用在我的机器上创建了一个基本的next-js应用程序
npx create-next-app@latest
安装SWA cli后,我运行
swa init
提示时输入配置名称。它显示了我的应用程序的以下检测到的配置。
Detected configuration for your app:
- Framework(s): React, Next.js
- App location: .
- Output location: .
- API location:
- App build command: npm run build
- API build command:
- App dev server command: npm dev
- App dev server URL: http://localhost:3000
? Are these settings correct? › (Y/n)
我说是
然后我运行
swa build
这将建立我的项目,并给我以下输出
Welcome to Azure Static Web Apps CLI (1.0.2)
Using configuration "my-next-app" from file:
/Users/bob/workspace/my-next-app/swa-cli.config.json
Build configuration:
- App location: .
- API location:
- Output location: .
- App build command: npm run build
- API build command:
Found package.json in .
Installing dependencies with "npm install"...
up to date, audited 229 packages in 757ms
77 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
Building app with npm run build in . ...
> my-next-app@0.1.0 build
> next build
info - Loaded env from /Users/bob/workspace/my-next-app/.env
info - Linting and checking validity of types
info - Creating an optimized production build
info - Compiled successfully
info - Collecting page data
info - Generating static pages (3/3)
info - Finalizing page optimization
Route (pages) Size First Load JS
┌ ○ / 5.35 kB 83.4 kB
├ └ css/ae0e3e027412e072.css 707 B
├ /_app 0 B 78 kB
├ ○ /404 182 B 78.2 kB
└ λ /api/hello 0 B 78 kB
+ First Load JS shared by all 78.3 kB
├ chunks/framework-09a2284fdc01dc36.js 45.5 kB
├ chunks/main-017a64f48d901a37.js 31.2 kB
├ chunks/pages/_app-620102ba3a9296b8.js 497 B
├ chunks/webpack-cc9c69bc14c8e1bc.js 750 B
└ css/ab44ce7add5c3d11.css 247 B
λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
○ (Static) automatically rendered as static HTML (uses no initial props)
然后我运行
swa deploy
提示时,我在Azure帐户中选择订阅。然后,当提示时,我在该订阅的门户中选择Azure静态应用程序
这是我得到的错误
Checking project settings...
✔ Choose your Static Web App › Test-SWA/Test-SWA
✔ Successfully setup project!
Deploying to environment: preview
Deploying project to Azure Static Web Apps...
✖ Failed to find a default file in the app artifacts folder (/). Valid default files: index.html,Index.html.
✖ If your application contains purely static content, please verify that the variable 'app_location' in your deployment configuration file points to the root of your application.
✖ If your application requires build steps, please validate that a default file exists in the build output directory.
我是next.js的新手现在我知道它找不到index.html,但那是因为它不存在。由于这都是js,所以当项目运行时,它们都会被渲染。所以我认为问题是,当我运行"swa-init"时,我的配置是不正确的,但由于我对next.js的知识差距,我无法找到正确的配置。我已经把它用于一个普通的react应用程序,因为它包含index.html文件。
我猜基于这篇文章:https://learn.microsoft.com/en-us/azure/static-web-apps/nextjs
预览中不支持通过SWA CLI进行部署。
很好奇你是否能让它发挥作用。