Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle new versions of vite-plugin-svelte (#382)
Fixes #381 There have been two changes in @sveltejs/vite-plugin-svelte that cause problems for us, which this PR addresses: - https://github.com/sveltejs/vite-plugin-svelte/releases/tag/%40sveltejs%2Fvite-plugin-svelte%401.0.0-next.42 started to merge the `svelte.config.js` file [by default](sveltejs/vite-plugin-svelte#317), which may not be what storybook users want / expect, since their production config may be different from the storybook config (same reason we don't automatically merge `vite.config.js`). With the changes here, the `configFile` option in `svelteOptions` can still be set to `true` or to a specific file, if desired. - https://github.com/sveltejs/vite-plugin-svelte/releases/tag/%40sveltejs%2Fvite-plugin-svelte%401.0.0-next.43 began [returning an array of plugins](sveltejs/vite-plugin-svelte#322) rather than just a single one. This would normally be fine, except that we hack around with the plugin to create two separate ones, with different names, to avoid HMR in story files. So, this PR checks to see if the result is an array or not, and reacts accordingly. Note, I'm throwing away the inspector for story files. This might be a problem, but until we hear about it, I think this'll be fine. The inspector is still pretty experimental anyway, from what I can tell. To test, you can revert the changes I've made in `vite-config.ts`, and you'll see that the `svelte` example breaks (I updated the svelte plugin in it). With the changes, it builds successfully. This also enables the use of the new experimental inspection plugin. ![image](https://user-images.githubusercontent.com/4616705/169103606-d04db266-5025-4e9d-8062-f894323adf77.png) To enable this feature, be sure you have `@sveltejs/vite-plugin-svelte` version `1.0.0-next.43` or higher, then add the following to your `svelteOptions` in `.storybook/main.js`: ```js module.exports = { // ... rest of config framework: '@storybook/svelte', svelteOptions: { preprocess: preprocess(), experimental: { inspector: true }, // <-- this line }, }; ``` Then, when the storybook opens, focus a story iframe and press cmd+shift (mac) or ctrl+shift (windows) to activate.
- Loading branch information