I have a Nuxt 3 application that I deploy to Azure Static Web App service in Azure DevOps pipeline.
After reading the configuration I've added some custom auth config and allowedRoles.
The problem I am facing is that the staticwebapp.config.json file contents is changed each time yarn run build
is run while at the same time nitro is configured to use Azure preset
export default defineNuxtConfig({
nitro: {
preset: 'azure',
}
}
Is there a way to disable the overwriting of the staticwebapp file, or add the Azure SWA configuration into the nitro: {in here?} config in the nuxt.config.ts file?
I have checked the documentation here and here but to no avail.
I have tried removing the preset: azure and observed that the staticweb.config.json file was unchanged, but then got error in DevOps pipeline saying no default file in output folder.
--- EDIT (and workaround) ---
As mentioned on the issue linked to in the comments section below, it is possible to overcome this obstacle by overwriting the generated staticwebapp.config.json with our own custom file with the help of a hook.
In the example below I move a custom config file I have made in a swa directory to the root of the application. The close hook runs after the Nitro server azure preset build.
export default defineNuxtConfig({
nitro: {
preset: 'azure'
},
hooks: {
'close': async () => {
const fs = require('fs/promises');
await fs.cp('./swa/staticwebapp.config.json', './staticwebapp.config.json', {force: true});
}
}
})