Home > Software engineering >  Firebase hosting using SvelteKit
Firebase hosting using SvelteKit

Time:08-10

I have created a svelte app and building app using SvelteKit everything is works fine.

I tried to deploy this app in firebase hosting but it fails. Sveltekit generating production build under .svelte-kit folder. I tried to change the public object value to ".svelte-kit" from firebase.json file but it returns error like there is no index.html and 404.html. What we need to change in firebase.json to make it work?

{
  "hosting": {
    "public" : "public",

    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

CodePudding user response:

While building svelte app for production we can configure build location to public using svelte.config.js file

   import adapter from '@sveltejs/adapter-static';

import preprocess from 'svelte-preprocess';

/** @type {import('@sveltejs/kit').Config} */
const config = {
    // Consult https://github.com/sveltejs/svelte-preprocess
    // for more information about preprocessors
    preprocess: [
        preprocess({
          postcss: true,
        }),
      ],

    kit: {
        adapter: adapter({
            pages: 'public',
            assets: 'public',
            fallback: null,
            precompress: false
            }),
            prerender: {
            default: true
            }
    }
};

export default config;

Here we should use @sveltejs/adapter-static adapter to build.

No need to change firebase.json we can leave it as it is

{
  "hosting": {
    "public" : "public",

    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}
  • Related