Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy purely static pages to SWA without creating a public subfolder #795

Open
doggy8088 opened this issue Jan 8, 2024 · 2 comments
Open
Labels
command: deploy All issues related to the deploy command priority: low (P2) Low priority scope: deploy-client Issues related to StaticSiteClient version: ga Issues related to major/GA releases

Comments

@doggy8088
Copy link

doggy8088 commented Jan 8, 2024

Is your feature request related to a problem? Please describe.

I'm always frustrated when deploying a static files onto SWA using the following command.

swa deploy --app-location . --deployment-token=<deployment-token> --env=production

All I have to do is move all files under current directory into a public sub-folder. Then run the following command.

swa deploy --app-location public --deployment-token=<deployment-token> --env=production

Describe the solution you'd like

I always wanted have a solution that can simply put my static files onto SWA. So I hope this command works.

swa deploy --app-location . --deployment-token=<deployment-token> --env=production

Or, more simple:

swa deploy --deployment-token=<deployment-token> --env=production

Or, even more simple if SWA_CLI_DEPLOYMENT_TOKEN env var has been set:

swa deploy --env=production

Describe alternatives you've considered

N/A

Additional context

I was deploying a Java application to a Web app on the App Service Plan with Linux OS. Due to I want to share the same App Service Plan and deploy a new web app that only have static files. (SPA)

In Web App with a App Service Plan for Linux OS, I'm not able to deploy a new Web App with only have static files. For Web App on Windows, there is no problem at all. For Web App on Linux, there is no way to deploy static files in a Web App that have a runtime stack. I don't want to create another App Service Plan by the way. So that the SWA is probably the only solution. So that I want the SWA CLI can provide a more intuitive and more simply way to deploy simple static pages/files.

I know I have many solutions to deploy static files such as Blob Storage. It because it doesn't support Custom Domain with a TLS certificate. So I don't want this solution either.

Related: #591

@doggy8088 doggy8088 changed the title Deploy purely static pages to SWA by creating a public subfolder Deploy purely static pages to SWA without creating a public subfolder Jan 8, 2024
@dankarmyy
Copy link

I ran into something similar you mention recently. However, the swa deploy command is supposed to work against the output from the swa build command.

The trick with purely static site is to make use of script commands in a package.json to copy your source to a directory that you can pass into the swa deploy command.

You'll need the following files (tweak commands/paths as necessary)

package.json

{
  "scripts": {
    "build": "robocopy src src\\dist /XD *dist* /s /purge > nul & if ErrorLevel 8 (exit /B 1) else (exit /B 0)"
  }
}

The above command will copy all source files from the src directory to src\dist, including sub directories but excluding the dist folder. It will also remove files in the dist that do not exist in the source. The additional command translates the non zero success exit code from robocopy to a zero exit code, otherwise it will fail.

swa-cli.config.json

{
  "$schema": "https://aka.ms/azure/static-web-apps-cli/schema",
  "configurations": {
    "app": {
      "appLocation": "src",
      "outputLocation": "dist",
      "appBuildCommand" : "npm run build"
    }
  }
}

Your project directory structure should look like this:

\
¬\src
¬\src\index.html
¬\src\staticwebapp.config.json
¬\src\any-other-files-or-directories
¬\src\dist
package.json
swa-cli.config.json

Then simply run the following command from your root directory (the one above \src):

swa build && swa deploy [options]

@doggy8088
Copy link
Author

I'm just hoping a better DX for the SWA newbies especially for the pure front-end devs. They might not know anything about Node.js or any backend stuff.

@adrianhall adrianhall added priority: low (P2) Low priority command: deploy All issues related to the deploy command version: ga Issues related to major/GA releases scope: deploy-client Issues related to StaticSiteClient labels Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
command: deploy All issues related to the deploy command priority: low (P2) Low priority scope: deploy-client Issues related to StaticSiteClient version: ga Issues related to major/GA releases
Projects
None yet
Development

No branches or pull requests

3 participants