Static Site Generation Config
Static site generation is created from the built in adapter, to create an adapter run:
npm run qwik add
Select Adaptor: Static site (.html files)
. Done!
Changes
Running the above command will make the following changes to your project:
- A
build.server
script will be automatically added to yourpackage.json
file. - A
adaptors/vite.config.ts
file will be created.
In node you can run the generation after building using:
node server/entry.ssr.js
Your build files will be generated into the dist
folder.
SSG Config
The adaptors/vite.config.ts
file also includes the SSG config, which would be custom for each implementation.
origin
The URL origin
, which is a combination of the scheme (protocol) and hostname (domain). For example, https://qwik.builder.io
has the protocol https://
and domain qwik.builder.io
. However, the origin
does not include a pathname
.
The origin
is used to provide a full URL during Static Site Generation (SSG), and to simulate a complete URL rather than just the pathname
. For example, in order to render a correct canonical tag URL or URLs within the sitemap.xml
, the origin
must be provided too.
If the site also starts with a pathname other than /
, please use the basePathname
option in the Qwik City config options.
outDir
The outDir
is a file system output directory where the static files should be written. In the example above, it's using Node's fileURLToPath to create an absolute file system path to write the static HTML files to.
Javascript Runtimes
For a Javascript project, it's quite common for the build's runtime to be built on top of Node.js. However, the core of Qwik City static site generation isn't tied to using only Node.js, which is why the qwikCityGenerate()
function is imported from @builder.io/qwik-city/static/node
. By scoping the generate function to a specific runtime, such as Node.js, this gives Qwik City the flexibility to also generate SSG from other runtimes in the future, such as Deno or Bun.