Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Avoid loading dynamic code out of node_modules directly #74

Closed
eamodio opened this issue Apr 22, 2021 · 6 comments · Fixed by #383
Closed

Avoid loading dynamic code out of node_modules directly #74

eamodio opened this issue Apr 22, 2021 · 6 comments · Fixed by #383
Assignees
Labels
bug Something isn't working
Milestone

Comments

@eamodio
Copy link

eamodio commented Apr 22, 2021

In the example code you showed loading the js file by getting its uri directly from the node_modules folder. That should be avoided, as we want extensions to be bundled and not ship their raw node_modules folder. So we should look into alternative ways of loading the library -- importing the js as a module or something along those lines. Though I'm not really thrilled with importing the lib directly into the extension, since it then adds size to the extension rather than just to the webview. So maybe there needs to be a bundle/webpack step or something that adds it in.

@eamodio eamodio added the bug Something isn't working label Apr 22, 2021
@hawkticehurst
Copy link
Member

Oh, thank you for this catch! I used the URI method early on to quickly pass the toolkit into the webview and test things out, but obviously forgot to switch back.

The toolkit actually already exports all of the components as separate ES modules on top of exporting a bundled lib toolkit.js file. So at least in terms of importing the library as a bunch of JS modules, we should be good.

But I agree that importing the lib/components directly into the extension feels less than ideal. Could you maybe extrapolate a bit more on what you were thinking with the idea of adding a bundle step that could add it into the webview?

@DragosMiloiuNXP
Copy link

I'm running into the same problem. I think that importing toolkit.js from node_modules is a bit awkward. Is there a better way to do this now?

@dzhavat
Copy link
Contributor

dzhavat commented Dec 3, 2021

What I did in one of my extensions was to manually copy the toolkit.min.js in own folder and use it this way. Not the best but until there's a better way, I'd continue doing that.

@hawkticehurst
Copy link
Member

hawkticehurst commented Dec 7, 2021

@DragosMiloiuNXP I still haven't had time to tackle this specific issue for vanilla-JavaScript-based extensions. I am currently working on a React-based sample extension that by proxy tackles this issue and should be finished sometime in early January.

With that said, if you're willing to use TypeScript for your webview code, I noted a few weeks ago that @orta (a member of the TypeScript compiler team) created an extension that:

I hope that's helpful in the meantime (until proper documentation can be created)!

Also if this doesn't solve your specific needs I would love to hear more about what you're hoping to do.

@DragosMiloiuNXP
Copy link

@dzhavat, @hawkticehurst Thank you for the answers.

After giving it some thought I decided to use react. So until January when the sample extension will be available, I have time to rewrite my code to use react.

@atanasster
Copy link

@DragosMiloiuNXP , I am already using react with webview-ui-toolkit and doing custom registration while looking forward to the release of the react wrappers.

If you would like to start now with react, take a look at my vscode extension:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants