For your Vite + React application deployed to Azure Static Web Apps, the correct values for app_location and output_location in your GitHub Actions workflow should be as follows:
- app_location: This should point to the folder where your application code resides, which is the root of your repository. Therefore, set it to
"/". - output_location: This should point to the folder where the built files are generated by Vite, which is
"dist"in your case.
Your GitHub Actions workflow should look like this:
- name: Deploy
uses: Azure/static-web-apps-deploy@v1
with:
action: "upload"
app_location: "/"
output_location: "dist"
skip_app_build: true
Regarding the issue where Azure is serving .js files with a MIME type of text/html, this typically happens when the routing configuration is not set correctly. In your staticwebapp.config.json, the route rule you have:
{ "route": "/*", "rewrite": "/index.html" }
This rule rewrites all requests to index.html, which can cause the server to return index.html for requests to your JavaScript files.
To fix this, you should add specific routes for your static assets (like JavaScript and CSS files) to ensure they are served correctly. You can modify your staticwebapp.config.json to include routes that exclude your static assets from being rewritten to index.html.
Here’s an example of how you might adjust your configuration:
{
"mimeTypes": {
".js": "text/javascript",
".mjs": "text/javascript",
".css": "text/css"
},
"routes": [
{ "route": "/dist/*", "serve": "/dist/*" },
{ "route": "/*", "rewrite": "/index.html" }
]
}
This configuration ensures that requests to files in the dist directory are served correctly without being rewritten to index.html.
References: