You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to build a rust web application in which I want to use a method for mapping file extensions to svg icon names. I am doing this without using a bundler (--target web). The function is defined in the gitlab/svgs package, which has its source on https://gitlab.com/gitlab-org/gitlab-svgs/ and can also be found on https://www.jsdelivr.com/package/npm/@gitlab/svgs. I tried various approaches at including this javascript in my app, but nothing worked without modifying the javascript itself.
My first approach was to download the source file, removing the module.exports and changing the getIconForFile function to export default function getIconForFile(name) and then using
but when calling getIconForFile(somestring) this leads to Uncaught (in promise) TypeError: ({fileNameIcons:{'.jscsrc':"json", '.jshintrc':"json",... - I think that getIconForFile is actually a javascript object, which itself has a method getIconForFile(s).
Ideally I would be able to import the module in the html file and then use the method from wasm, to make it possible to update the source of the file during runtime. So I tried
<script type="module">
import gitlabsvgs from 'https://cdn.jsdelivr.net/npm/@gitlab/[email protected]/+esm';
import init from '/static/js/pkg/myproject_wasm.js';
await init();
</script>
and then accessing gitlabsvgs using wasm_bindgen, but that didn't work either.
Does anyone have an idea how to use that method from rust? I don't really have much knowledge about javascript and different package types is, so maybe there is some misunderstanding about how this package can even be used directly in a webpage...(but when I add window.myModule = gitlabsvgs a can run the method ...)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
I'm trying to build a rust web application in which I want to use a method for mapping file extensions to svg icon names. I am doing this without using a bundler (
--target web
). The function is defined in thegitlab/svgs
package, which has its source on https://gitlab.com/gitlab-org/gitlab-svgs/ and can also be found on https://www.jsdelivr.com/package/npm/@gitlab/svgs. I tried various approaches at including this javascript in my app, but nothing worked without modifying the javascript itself.My first approach was to download the source file, removing the
module.exports
and changing thegetIconForFile
function toexport default function getIconForFile(name)
and then usingThis works, but I guess it should be possible to use the existing packaged
gitlab/svgs
package. I first tried to use it directly:but when calling
getIconForFile(somestring)
this leads toUncaught (in promise) TypeError: ({fileNameIcons:{'.jscsrc':"json", '.jshintrc':"json",...
- I think thatgetIconForFile
is actually a javascript object, which itself has a methodgetIconForFile(s)
.Ideally I would be able to import the module in the html file and then use the method from wasm, to make it possible to update the source of the file during runtime. So I tried
and then accessing
gitlabsvgs
using wasm_bindgen, but that didn't work either.Does anyone have an idea how to use that method from rust? I don't really have much knowledge about javascript and different package types is, so maybe there is some misunderstanding about how this package can even be used directly in a webpage...(but when I add
window.myModule = gitlabsvgs
a can run the method ...)Beta Was this translation helpful? Give feedback.
All reactions