Search code examples
sveltesapper

How to set the base tag href attribute in Sapper?


How can I modify the value of the <base> href attribute in Sapper ?

As per the documentation, I tried sapper export --basepath foldername which (correctly) creates a foldername folder in __sapper__/export but does not update the base tag href value with the expected "/foldername" value in the created index.html file. The output stays <base href="/" />

My goal is to deploy my SPA on a GitHub Pages subfolder.


Solution

  • One way I just found is to edit /src/server.js and use the first argument:

        .use(
            'foldername',  // <-- here
            compression({ threshold: 0 }),
            sirv('static', { dev }),
            sapper.middleware()
        )