I separated my .svelte
, .ts
and .scss
in 3 distinct file eveything work but the linting in VSCode isn’t working
Question posted in Visual Studio Code
View the official documentation.
View the official documentation.
I separated my .svelte
, .ts
and .scss
in 3 distinct file eveything work but the linting in VSCode isn’t working
2
Answers
You cannot separate script code from a Svelte component like this.
All variables that are part of the template have to be in the file, otherwise you will lose all reactivity (unless you use module
import
statements and work exclusively with stores). You also would not be able to declare component properties.Just do not do this.
If you want to import it from a seperate file, you can use ES6 imports and exports to do this:
Svelte’s tutorials, however, (unless the script file is very big), usually inline the script into the .svelte file as so:
However, the way you’re doing it can not be done with a svelte component. If you’re trying to import an external JS file, you can put it in your
index.html
file or find the proper library that will import it for you.