What causes "some" to be undefined in vite-plugin-sveltekit-compile? #11429
Replies: 2 comments 1 reply
-
Uh no, I ended up here because I have the same issue and saw |
Beta Was this translation helpful? Give feedback.
-
I was had the same issue a while back, subscribed to the discussion. A few months ago I found the solution, but forgot to share. You have to use the svelte plugin when you want to get a js bundle. - import { sveltekit } from '@sveltejs/kit/vite';
+ import { svelte } from '@sveltejs/vite-plugin-svelte';
import { defineConfig } from 'vite';
export default defineConfig({
...
plugins: [
- sveltekit()
+ svelte()
],
...
});
I use 2 separate vite configs. The first one (uses thesveltekit plugin), for messing around and developing custom components. The other one (uses the svelte plugin) bundles everything in to a single bundles, I run this on a each component separately so I can import only the components I need. For a reference, in case I am missing something. Here is the Vite config and command that I use to build components in to separate bundles.
import { svelte } from '@sveltejs/vite-plugin-svelte';
import { type BuildOptions } from 'vite';
import { defineConfig } from 'vitest/config';
import fs from 'fs';
export default defineConfig(() => {
const args = process.argv;
if (!args.includes('--component-input')) {
throw new Error('Missing --component-input argument');
}
let inputFile: string | string[] = args[args.indexOf('--component-input') + 1];
if (!fs.existsSync(inputFile)) {
throw new Error(`File ${inputFile} does not exist`);
}
return {
plugins: [svelte()],
resolve: { alias: { $lib: '/src/lib' } },
build: {
outDir: 'dist',
rollupOptions: {
input: inputFile,
output: {
format: 'umd',
entryFileNames: '_[name].wc.js'
}
} as BuildOptions['rollupOptions'],
emptyOutDir: false
},
test: {
include: ['src/**/*.{test,spec}.{js,ts}']
}
};
}); |
Beta Was this translation helpful? Give feedback.
-
I am trying to build a svelte component as an es module using vite library mode but I can't make it build. It feels like I am missing something basic.
This is the error:
This is my vite.config.js file:
And this is my index.js file:
Link to reproducible example.
Link to stackoverflow issue.
Any help is much appreciated!
Beta Was this translation helpful? Give feedback.
All reactions