Support importing Svelte components without extension
See original GitHub issueIs your feature request related to a problem? Please describe.
I have some complex components with many subcomponents. The subcomponents are private and come together to make one large component.
Here’s an example:
form/
input.svelte
textarea.svelte
index.svelte
radio.svelte
checkbox.svelte
Describe the solution you’d like
I’d like to be able to resolve form/
to form/index.svelte
rather than explicitly writing form/index.svelte
.
I think this plugin by default should follow node.js-style resolution for files that have the .svelte extension.
form/ => form/index.svelte
form/input => form/input.svelte (or form/input/index.svelte)
form/input.svelte => form/input.svelte
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top Results From Across the Web
rollupjs - import svelte component ommiting .svelte extension
You can add a resolver to your configuration with @rollup/plugin-node-resolve : rollup.config.js
Read more >Componentizing our Svelte app - Learn web development
In Svelte, an application is composed from one or more components. A component is a reusable, self-contained block of code that encapsulates ...
Read more >Svelte Component Extensions - Framework7
After Svelte mounts the app and init Framework7, we will have access to Framework7's initialized instance and some other useful properties that can...
Read more >unplugin-svelte-components - npm
Use components as you would usually do, it will import components on demand, and there is no import required anymore! It will automatically...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In case you want to know Rich’s feelings on this: https://twitter.com/Rich_Harris/status/1002959357250801664 - and those are also the same as Ryan Dahl, creator of Node.
I too agree. Just because you can resolve files without an extension, doesn’t mean you should.
I’m against this, because you then have no distinction anymore which file is a Svelte file and which file is a normal file. What happens if you have
index.js
andindex.svelte
in the same folder? What should be imported? This would be a breaking change. Also it is not supported by the bundlers either as far as I know.For your specific case, I suggest to add a
index.js
with the following contents:And then import it like