question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support importing Svelte components without extension

See original GitHub issue

Is 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

11reactions
antonycommented, Sep 23, 2020

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.

10reactions
dummdidummcommented, Sep 23, 2020

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 and index.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:

export { default as Index } from './index.svelte';
// ... you can add your other Svelte files here as well

And then import it like

<script>
   import { Index } from './form';
</script>
Read more comments on GitHub >

github_iconTop 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 >
Docs • Svelte
Complete documentation for Svelte.
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found