How to define global variables?
See original GitHub issueI have a svelte component rendered within another app. That app defines some global variables which I’d like to use.
Whenever I use a custom variable (like config
) I get a warning:
(!) Plugin svelte: 'config' is not defined
src/Customize.svelte
41:
42: <svelte:head>
43: <link rel="stylesheet" href={`${config.relative_path}/styles.css`} />
^
44: </svelte:head>
45:
I cannot, for the life of me, find a way to add known global variables to avoid the warning.
I know I could provide onwarn
but that seems hacky and would suppress warnings for actual issues.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Python - Global Variables - W3Schools
Variables that are created outside of a function (as in all of the examples above) are known as global variables. Global variables can...
Read more >Global Variable in Python With Examples [Updated] | Simplilearn
A global variable in Python means having a scope throughout the program. Understand how to create and access global variables with examples.
Read more >Declare global variables - IBM
A global variable has its value stored in memory and is available to other SPL routines, run by the same user session, on...
Read more >Global Variables in C - GeeksforGeeks
The global variables get defined outside any function- usually at the very beginning/top of a program. After this, the variables hold their ...
Read more >Python Global Variables – How to Define a ... - freeCodeCamp
How to Create Variables With Global Scope in Python ... When you define a variable outside a function, like at the top of...
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 Free
Top 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
To be clear, I came into this thinking I had just missed something. Yes this would be a feature request, and probably one to actually apply to the svelte compiler, not the rollup plugin. I understand that the code I gave is currently the suggested solution, but given that many other tools (typescript, eslint, etc) have this ability, it isn’t ideal for supporting global vars.
I’ll close this because rollup global imports is probably a better solution, and because this feature would need to be implemented in the svelte compiler. At least other people will now have an answer if they go looking.
I believe the term you’re looking for is “feature request”