I'm moving my existing StaticSiteTemplate project over to SvelteKit, a cool framework capable of building static sites. Even though SvelteKit offers a lot of additional functionality beyond my original Gulp-powered template, this template produces a faster dev experience and fewer dependencies.
This is for my own use and I don't have any plans to elevate it beyond my own needs, but you're welcome to take it and build on it from there. (Unless you prefer indenting with spaces, in which case GTFO.)
I've preconfigured this template to be more amenable to the style of development that I prefer.
staticwebapp.config.json
file to configure basic settings.Download and install the latest stable versions of these products from their websites.
Whenever picking up a new version of the template, you need to make sure your dependencies are installed. In Visual Studio Code:
Then, you can do a full production build of the project with:
But, the most useful option will be the Start task, which starts the SvelteKit dev server, which starts instantly, watches for changes, and all sorts of cool stuff that I can't take credit for.
To see the status of the server or build task, click the tools icon in the status bar, or Terminal > Show Running Tasks.
To debug browser code in Visual Studio Code:
If you want to use the project without Visual Studio Code, use the following scripts instead of the above:
npm install
: Install dependenciesnpm start
: Start dev servernpm run build
: Production buildnpm run serve
: Serve production build for testingBy default, the site will only be served to your local machine on port 80. If you want to expose the server to your whole local network, add --host
to the commands in package.json
.
Important: See this Vite.js issue for an overview of security concerns before doing this.
At minimum, do this to customize the site for your purposes:
SvelteKitTemplate
with the name of your sitesrc/routes/__layout.svelte
static/images/app
with appropriate logos for your sitehumans.txt
.github/workflows/publish.yml
since Azure Static Web Apps will automatically add a publishing workflow for you.staticwebapp.config.json
and remove the Create redirects
task from the deployment workflow..github/workflows/publish.yml
since it won't work. Or, use it as a starting point and remove the Azure-specific actions.Use staticwebapp.config.json
to configure routes and redirects for the app. The workflow will generate the appropriate redirect page files.
Depending on how you deploy:
* Azure Static Web Apps: You can use the full capabilities of this file, such as adding custom headers, URL rewrites, and so on.
* Azure Blob Storage: Everything other than the routes
array in this file will be ignored.
* Other static hosts: This functionality will only work if you use the create-redirects
GitHub Action. Everything other than the routes
array in this file will be ignored.
{
"routes": [
{ "route": "default.aspx", "redirect": "/" }
]
}
You have a few options:
You can deploy to Azure Static Web Apps with very minimal configuration:
build
.Once your repo and Azure are set up in this way, whenever your default branch is changed, GitHub will automatically build your site and publish it to Azure without any manual steps.
Tip: You can test your Azure Static Web App locally:
npm install -g @azure/static-web-apps-cli
)npm run build
swa start build --port 80
You can easily deploy to an Azure Blob Storage static website using GitHub Actions (if your project is on GitHub):
.github/workflows/publish.yml
, edit it, and uncomment the two push:
and branches: [ $default-branch ]
lines at the top to enable automatic deployments.Once your repo is set up this way, whenever your default branch is changed, GitHub will automatically build your site and publish it to Azure without any manual steps.
Tip: You can use my deploy-to-azure-storage
Action to automatically deploy static sites built with other templates, too.
You can also deploy the site to any static file host. Just run a production build (npm run build
; see above) and upload the contents of the build
folder to a host of your choice.
The deployment workflow included with this template can also automatically purge an associated Azure CDN endpoint whenever the site's contents change, to minimize the length of time when files are stale. Open .github/workflows/publish.yml
on github.com, and see the instructions near ENABLE_CDN_PURGE
. Note that CDN purging requires a separate secret in addition to the DEPLOY_SAS_URL
secret you already set up.
This template is © 2020-2023 Travis Spomer but released to the public domain under the CC0 1.0 license. This license does not apply to sites built with this template, nor to external libraries referenced by this template; only the template itself. It is provided as-is and no warranties are made as to its functionality or suitability.