Skip to content

Commit

Permalink
Do not add vite-plugin-svelte
Browse files Browse the repository at this point in the history
  • Loading branch information
IanVS committed Aug 26, 2022
1 parent 61e08d6 commit b521eed
Showing 1 changed file with 0 additions and 45 deletions.
45 changes: 0 additions & 45 deletions code/frameworks/svelte-vite/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,51 +21,6 @@ export function readPackageJson(): Record<string, any> | false {
export const viteFinal: StorybookConfig['viteFinal'] = async (config, { presets }) => {
const { plugins = [] } = config;
const svelteOptions = await presets.apply<Record<string, any>>('frameworkOptions');
try {
// eslint-disable-next-line global-require
const sveltePlugin = require('@sveltejs/vite-plugin-svelte').svelte;

// We need to create two separate svelte plugins, one for stories, and one for other svelte files
// because stories.svelte files cannot be hot-module-reloaded.
// Suggested in: https://github.com/sveltejs/vite-plugin-svelte/issues/321#issuecomment-1113205509

// First, create an array containing user exclude patterns, to combine with ours.

let userExclude = [];
if (Array.isArray(svelteOptions?.exclude)) {
userExclude = svelteOptions?.exclude;
} else if (svelteOptions?.exclude) {
userExclude = [svelteOptions?.exclude];
}

// These are the svelte stories we need to exclude from HMR
const storyPatterns = ['**/*.story.svelte', '**/*.stories.svelte'];
// Non-story svelte files
// Starting in 1.0.0-next.42, svelte.config.js is included by default.
// We disable that, but allow it to be overridden in svelteOptions
plugins.push(sveltePlugin({ ...svelteOptions, exclude: [...userExclude, ...storyPatterns] }));
// Svelte stories without HMR
const storySveltePlugin = sveltePlugin({
...svelteOptions,
exclude: userExclude,
include: storyPatterns,
hot: false,
});
plugins.push({
// Starting in 1.0.0-next.43, the plugin function returns an array of plugins. We only want the first one here.
...(Array.isArray(storySveltePlugin) ? storySveltePlugin[0] : storySveltePlugin),
name: 'vite-plugin-svelte-stories',
});
} catch (err) {
if ((err as NodeJS.ErrnoException).code === 'MODULE_NOT_FOUND') {
throw new Error(
'@storybook/builder-vite requires @sveltejs/vite-plugin-svelte to be installed' +
' when using @storybook/svelte.' +
' Please install it and start storybook again.'
);
}
throw err;
}

// eslint-disable-next-line global-require
const { loadSvelteConfig } = require('@sveltejs/vite-plugin-svelte');
Expand Down

0 comments on commit b521eed

Please sign in to comment.