Fast static website generator with progressive enhancement - based on Svelte and Snowpack, inspired by svelvet.
Now and then I have to build a mostly static website that does not need a fancy server. It seems wrong to serve an empty html shell only to load a script that builds the DOM.
Existing generators are a bit too powerful/opinionated for my taste.
A very simple cli renders .svelte
files in src
to hydratable .html
and copies
other files.
npm i --save-dev PKlknr/svatic
npx svatic
Now, when you create e.g. src/Index.svelte
, it will create dest/index.html
and
serve it with live-reloading.
watch
and build
take the same options. serve
takes additional servorOptions
.
watch will only rebuild changed files and files that depend on them. It's fast!
const {watch, build, serve} = require('svatic');
serve({
pageMap: [
{src: 'Index.svelte', dest: 'index.html'},
{src: 'Privacy.svelte', dest: 'privacy.html', hydratable: true},
{src: 'Contact.svelte', dest: 'imprint.html'},
],
}).then(() => console.log('done'))
const dev = process.env.NODE_ENV !== 'production';
const srcDir = './src';
const destDir = dev ? './out' : './dist';
const pageMap = [
{src: 'Index.svelte', dest: 'index.html'},
// hydratable tells build to hydrate the page
{src: 'Privacy.svelte', dest: 'privacy.html', hydratable: true,},
// props are passed to the root component
{src: 'Contact.svelte', dest: 'imprint.html' props: {lang: 'en'}},
];
// Define some tasks needed for a full website
const dirs = () => ...
...
serve({
srcDir, // (./src) - pageMap[].src is relative to this
destDir, // (./dist) - write here
pageMap, // don't want to dictate a structure. May accept function in the future
// hooks: All hooks are run on start. When watching, hooks are run when
// their filter returns true.
hooks: [
{task: dirs},
{task: installFonts},
{filter: filename => filename.endsWith('.css'), task: buildTailwind},
{filter: filename => filename.includes('src/img'), task: images},
],
afterBuild, // (noop) - function that is called after each build. First
// param is error if apllicable
// servorOptions are passed to servor
servorOptions: {port: 3000},
});
See example/src
We include the whole html-document in a Svelte-component, so we don't need to crawl a site.
Note: This depends on https://github.com/sveltejs/svelte/pull/4309
This is heavily inspired by what svelvet does.
Turns .svelte into .svelte.js. Points at web_modules.
Build a map of dependencies for each page. On change, rebuild the changed file and all files depending on it.
git clone https://github.com/PKlknr/svatic
cd svatic
npm i
node example/build.pureHtml.js
node example/build.hydrate.js
... and have a look at example/*/out