kisstkondoros / gutter-preview

Other
158 stars 37 forks source link

The parameter "gutterpreview.paths" #48

Closed ktulho closed 5 years ago

ktulho commented 5 years ago

Sorry for my English I use Yandex translator. Could someone give an example for the parameter "gutterpreview.paths". Thanks.

kisstkondoros commented 5 years ago

Thanks for reaching out, the feature was orignally requested in #21. It tries to mimick the path option which you might be familiar from typescript's tsconfig.json.

See the path mapping section of https://www.typescriptlang.org/docs/handbook/module-resolution.html.

If you already have a jsconfig.json or tsconfig.json you can define path aliases like it is defined in the linked article and this extension will pick them up automatically (a restart might be necessary after changing it).

By using path aliases so you could reduce lengthy import statements into shorter ones. If you use a bundler like webpack and you configure it properly it might also be used for images and that's when this feature is useful.

e.g. if you have a tsconfig.json which contains paths like:

"paths": {
    "@icons/*": ["assets/icons"],
    "@assets/*": ["assets"]
}

then you can shorten the paths to assets/icons e.g. assets/icons/favicon.ico to @icons/favicon.ico.

If you don't use any bundler or some sort of post processing it will not work!

Sorry for the lenghty explanation, but I was not sure which level of introduction you actually need.