Skip to content

Support for code loaded from external script src tag #1511

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

Closed
Hecatron opened this issue Jun 4, 2022 · 2 comments
Closed

Support for code loaded from external script src tag #1511

Hecatron opened this issue Jun 4, 2022 · 2 comments

Comments

@Hecatron
Copy link

Hecatron commented Jun 4, 2022

I'm fairly new to svelte, but one of the tricks I noticed that works
is that you can place the code for a svelte component into a seperate file such as

example1.svelte

<script lang="ts" src="./example1.svelte.ts"></script>

<button class="btn" on:click={handleClick}>
	clicks2: {count}
</button>

example1.svelte.ts

let count = 0;
	
export function handleClick() {
    count += 2;
}

This seems to build and work fine similar to the way vue supports placing the template and code into separate files for separation of concerns.
you can also nest the files in the file explorer with something like this

    "explorer.fileNesting.patterns": {
        "*.svelte": "${capture}.svelte.ts, ${capture}.svelte.js, ${capture}.svelte.css, ${capture}.svelte.scss"
    },

However it looks like the svelte extension for vscode doesn't like it all that much
It complains about the count property and handleClick function not being defined

Also for the script tag I noticed the extension doesn't support self closing tags yet
but I think that's related to #299

# Works ok
<script lang="ts" src="./example1.svelte.ts"></script>
# Complains about a missing end tag
<script lang="ts" src="./example1.svelte.ts" />

I had a rumage through the settings but couldn't find anything related to the above.

@dummdidumm
Copy link
Member

Duplicate of #936

@dummdidumm dummdidumm marked this as a duplicate of #936 Jun 4, 2022
@Hecatron
Copy link
Author

Hecatron commented Jun 4, 2022

ah sorry I did search for an existing issue but missed that one

@Hecatron Hecatron closed this as completed Jun 4, 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

No branches or pull requests

2 participants