Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile each .svelte component file into separate webcomponent .js file

How can I compile each .svelte component into separate webcomponent .js file? for example DatePicker.svelte -> DatePicker.js FileUploadArea.svelte -> FileUploadArea.js

Thank you!

like image 368
Nabeel Ali Avatar asked Nov 22 '25 20:11

Nabeel Ali


1 Answers

You can create the a new vite.split.config.js & use that in the build process & in the input array of rollupOptions you can define the svelte components paths you want to export. Then build with -c vite.split.config.js flag.

import {defineConfig} from 'vite';
import {svelte} from '@svelte.js/vite-plugin-svelte';

export default defineConfig({
   build: {
      rollupOptions: {
        input: ['./src/lib/Button.svelte'],
      }
   },
   plugins: [
    svelte({
        compilerOptions: {
            customElement: true,
        },
     })
  ]
});

You can find more details on the Log Rocket Blog

like image 78
usmany Avatar answered Nov 25 '25 08:11

usmany



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!