sveltesnowpackroutify

How to use Routify with Snowpack and Svelte


I need to install Routify to Svelte app which is running with Snowpack.

Current documentation is very narrow and only shows an installation with Rollap.

I've tried a template to achieve it but I get errors on the Routify side.

How can I achieve this?

Any help is very much appreciated. Also open to any other Path-based SPA router recommendations that work well with Snowpack.


Solution

  • Found a solution. Started a project with an official Snowpack template using npx create-snowpack-app [DIR NAME] --template @snowpack/app-template-svelte-typescript (Replace [DIR NAME] with folder name).

    And then did everything below:

    Install npm-run-all:

    npm i npm-run-all
    

    /package.json:

    "scripts": {
        "dev": "run-p routify snp",
        "build": "routify -b && routify export && snowpack build",
        "test": "web-test-runner \"src/**/*.test.js\"",
        "routify": "routify",
        "snp": "snowpack dev",
    },
    ...
    "routify": {
        "extensions": "svelte,html,svx,md",
        "dynamicImports": false,
        "routifyDir": "src/.routify"
    }
    

    /snowpack.config.js:

      packageOptions: {
        knownEntrypoints: ["@roxi/routify/runtime/buildRoutes"]
      },