Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: open file inspector #322

Merged
merged 12 commits into from
May 6, 2022
Merged

Feat: open file inspector #322

merged 12 commits into from
May 6, 2022

Conversation

dominikg
Copy link
Member

@dominikg dominikg commented May 2, 2022

Inspired by vite-plugin-vue-inspector and it's svelte sibling https://github.com/tanhauhau/vite-plugin-svelte-inspector, this PR bakes it into vite-plugin-svelte as an experimental option.

To use it, set experimental:{inspector: true} either inline on vite-plugin-svelte definition or in your svelte config.
Use custom InspectorOptions to customize it's behavior

@dominikg dominikg requested a review from bluwy May 5, 2022 21:35
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good 👍 Works well locally for me.

The only small quirk so far is that on macos, using holdMode: true, ctrl-shift doesn't really work as ctrl-click is considered a right click and it doesn't look like it can be prevented. Maybe we can set meta-shift as the default for macos, rest be ctrl-shift for a nicer experience.

@dominikg dominikg merged commit 5a002c7 into main May 6, 2022
@dominikg dominikg deleted the feat/open-file-inspector branch May 6, 2022 19:32
@github-actions github-actions bot mentioned this pull request May 6, 2022
IanVS added a commit to storybookjs/builder-vite that referenced this pull request May 18, 2022
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.
@github-actions github-actions bot mentioned this pull request Jul 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants