Home > database >  How can I switch from rollup/vite to webpack for sveltekit?
How can I switch from rollup/vite to webpack for sveltekit?

Time:05-20

The node polyfill isn't working for us on rollup/vite. We need to switch to webpack.

Is there any official documentation on how to use sveltekit with webpack?

Here is our svelte.config.js file:

import adapter from '@sveltejs/adapter-static';
import preprocess from 'svelte-preprocess';
import path from 'path';
// import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
import dotenv from 'dotenv-flow';

dotenv.config();
const config = {
    preprocess: preprocess(),
    kit: {
        adapter: adapter({
            // default options are shown
            pages: 'build',
            assets: 'build',
            fallback: 'index.html',
            precompress: false
        }),
        vite: {
            optimizeDeps: {
                esbuildOptions: {
                    // Node.js global to browser globalThis
                    define: {
                        global: 'globalThis'
                    }
                    // Enable esbuild polyfill plugins
                    // plugins: [
                    //  NodeGlobalsPolyfillPlugin({
                    //      buffer: true,
                    //      global: true,
                    //      process: true,
                    //      url: true,
                    //      assert: true,
                    //      crypto: true,
                    //      http: true,
                    //      https: true,
                    //      os: true,
                    //      stream: true
                    //  })
                    // ]
                }
            },
            resolve: {
                alias: {
                    $components: path.resolve('./src/components'),
                    $stores: path.resolve('./src/stores'),
                    $api: path.resolve('./src/api'),
                    $node: path.resolve('./node_modules')
                }
            },
            build: {
                minify: false
            }
        }
    }
};

export default config;

CodePudding user response:

You can't switch it. SvelteKit is highly dependent on Vite—so much so it's possible it'll even be shipped as a Vite plugin at some point.

If you really exhausted your options with Vite and decided you must use Webpack, an option would be to isolate all the code that requires it into a separate package which you can then prebundle with Webpack and consume from the SvelteKit app.

  • Related