rixo / svench

A lightweight workbench to develop your Svelte components in isolation
svench-docs.vercel.app
207 stars 6 forks source link

How to integrate? #2

Open Wolfr opened 4 years ago

Wolfr commented 4 years ago

Let's say I have this super simple dir structure with a few svelte components.

image

How would I integrate Svench in a good way? Do I place a svench dir inside my project and reference files outside using folder backtracking? (../../src/Badge.svelte)

Wolfr commented 4 years ago

The repo: https://github.com/Wolfr/jui

rixo commented 4 years ago

It really depends on what you're doing... This is not something I intend Svench to be opinionated about.

As a developer who uses it as a development tool (i.e. my components mostly go from 0 to almost 100% being developed in the workbench before they are dropped into the actual application), I just put the .svench file beside the component they're documenting.

./src/components/Foo.svelte
./src/components/Foo.svench

So referencing the target component is never a hassle for me, it's just one dot away. Also, I'm very happy with having the menu hierarchy in Svench mirror the layout of my source directory.

Now I understand that you might want to have a dedicated Svench folder to be able to control your pages (i.e. menu) layout, or just because you don't like collocating different concerns in the same place. In this case, yes, you'll need to be able to reference the target components in a way your system / bundler will understand (we're not going to overload Node's resolution algorithm).

In this case, I'd personally avoid importing paths like ../../src/Badge.svelte though, because they're impractical and way too sensible against refactors. I would have an alias to my src folder so that I'd import this as @/Badge.svelte from anywhere (generally implemented with a symlink svench/node_modules/@ -> .. because all IDE tooling automatically support that -- sometime need to double with aliases from the bundler down the road, because some deployment envs don't support symlinks).

rixo commented 4 years ago

I realize I answered this as a support question, but the truly interesting question here is: how do you want to integrate?

The main use case I'm considering is something like this:

How the last point will be tackled is still very much an open question. We'll need a dedicated index.html, a web server, etc... How to make this the most frictionless for the user?

That being said, I know that you have quite different perspectives, so I'd love to hear about your own ideal scenario and, also, it would help me greatly if you can help me draw the specs on this question (generally).

What would be the best way for you to integrate Svench into your project?