How to avoid Foundry Globals from causing vite build warnings?
I'm getting a lot of warnings from
vite-plugin-svelte
for foundry globals like TextEditor.enrichHTML(item.system.description.value || '')
. Any idea how I can make it ignore those or register them?
E.g.:
12 Replies
define them?
The code editor will of course bring up errors for things it doesnt see or know
How would I define it?
I'm not worried about the code editor but I'd like the vite build to be clean, or at least alerting me to actual issues, not nonsense issues.
Through types
you can make a typedoc, install some foundry types like the one I have or from League of Extraordinary Developers, or disable the typechecking completely
Unfortunately I don't know how to do any of that. Tx for the feedback though.
some foundry types like the one I have
Do you mean this? https://github.com/MrVauxs/pf2e-graphics/blob/main/src/extensions.d.ts?
I'm confused by that because types are a TypeScript thing, but this warning is from vite-plugin-svelte, which isn't related to TypeScript (I don't think).I was referring to this https://github.com/MrVauxs/pf2e-graphics/blob/842c50374ff67e46f55b1978748a5d87ddb28310/tsconfig.json#L34
This is normal IDE typechecking, its not unique to Typescript, Javascript also has basic functionality of saying "I think you made a typo, this variable doesnt exist"
In either case you have to provide the global variables yourself
You have to either make a
tsconfig
or jsconfig
file and figure out how to point it at your Foundry install, or install types as a dependency
Then the IDE will see all the newly added types including TextEditor
You can also make your own .d.ts
file and declare the global variables yourself
You can also use an editor like WebStorm and give it the Foundry folder, and it will find the types by itself
Or ignore it
It'll work when it runsOk thx appreciate the effort. It's still clear as mud to me though 😅 I'm not sure what the IDE has to do with it as these errors are produced by
yarn build
. I also don't know how to do any of the things you describe, so I guess I'll have to live with the warnings.I thought you were seeing these in the IDE.
In either case, the plugin is for checking the validity of your files, just like an IDE would if given the appropriate setup. And it finds a value it doesn't recognize.
GitHub
vite-plugin-svelte/docs/config.md at main · sveltejs/vite-plugin-sv...
Svelte plugin for http://vitejs.dev/. Contribute to sveltejs/vite-plugin-svelte development by creating an account on GitHub.
Here
You can just disable it
I gather you are trying to use Foundry globals directly in Svelte templates. The answer is simple... don't do that... Set whatever values you'd like to a variable in the script portion of the component and reference that local script variable from the component in the template.
When Svelte processes the template portion of a component it doesn't know anything about the runtime environment including the many additional Foundry global variables.
That is why there is the
gameState
holding store in the off chance that it is more convenient to access game
directly in the template, but otherwise set a local variable in the script portion.