Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please can you optimize the size of the VSCode extension #139

Open
mgholam opened this issue May 30, 2020 · 13 comments
Open

Please can you optimize the size of the VSCode extension #139

mgholam opened this issue May 30, 2020 · 13 comments

Comments

@mgholam
Copy link

mgholam commented May 30, 2020

Is your feature request related to a problem? Please describe.
Please can you optimize the on disk size of the VSCode extension (i.e. smaller than 150mb)

Describe the solution you'd like
By possibly pre-building the extension before publishing.

@dummdidumm
Copy link
Member

@orta can we do anything about this? I'm not sure how the publish-to-marketplace stuff works and how we could add a bundle/minify step before that.

@orta
Copy link
Contributor

orta commented Jun 8, 2020

The official recommendations are here: https://code.visualstudio.com/api/working-with-extensions/bundling-extension

Basically it's 'move to webpack'

@dummdidumm
Copy link
Member

Tried with a rollup config, but no success.

So far I have:

  • One rollup config for the language-server. It builds the package into a single file
  • One rollup config for svelte-vscode. It build the extension into a single file
  • A deploy script in svelte-vscode which takes care of executing both these rollup builds and then replacing the contents of dist in node_modules/svelte-language-server in svelte-vscode with the built output. Reason: That way the require.resolve(...) in extension.ts will still work
  • Added ignore for all node_module content except that of svelte-language-server. Since svelte-language-server/dist contains everything it needs, other modules are not relevant anymore. They still need to be present during deployment though so vsce does not throw errors.

Yes, this all feels very hacky 😄

Problems:

  • Inside the language server, there is some dynamic require.resolve stuff. This does not work well with the current rollup config, as, well, those are all bundled now and not found anymore like that. Don't know how to solve this.

@mgholam
Copy link
Author

mgholam commented Jun 9, 2020

I did this https://github.com/mgholam/svelte-multi-page-app with one rollup.config.js if it helps.

@dummdidumm
Copy link
Member

Down to less than 90mb now. Since we do some dynamic requires/depending on node_modules resolution at runtime and that is very tricky in combination with bundling, I will not explore bundling further for now.

@mgholam
Copy link
Author

mgholam commented Jun 16, 2020

What kind of numbers are we looking at if all goes well (currently at 80mb)?

The biggest folder is "typescript" at 54mb right now.

@dummdidumm
Copy link
Member

Honestly I don't know, but with bundling and minification I assume it could go down to less than 10mb.

@mgholam
Copy link
Author

mgholam commented Aug 5, 2020

Can you give me a starting point, so I can have a crack at this?

@dummdidumm
Copy link
Member

Not really I'm afraid. I would try webpack (my attempt with rollup failed) and then try to write a config to bundle the extension (packages/vs-code). Pitfalls are the dynamic require-calls which need to work after bundling.

@mgholam
Copy link
Author

mgholam commented Aug 5, 2020

How can we keep the require.resolve() calls and just delete the node_modules\typescript folder in the output (50Mb saving)?

@dummdidumm
Copy link
Member

You mean we don't bundle and instead just delete typescript from the output? I don't know if this will work, you could try it out yourself.

  • bundle the extension locally to vsix (vsce package)
  • delete node_modules/typescript from the output (you can just use zip to look into the bundle)
  • install the vsix manually as a VSCode extension
  • test if everything works

@jasonlyu123
Copy link
Member

Just find out vetur actually vscodeignore a lot of files in node_modules/typescript. We probably could also do this since typescript outputs multiple different builds for different purposes. And we didn't use most of them. We can further optimize it to also strip localization files. We also didn't use it now.

Another potential optimization is prettier. Prettier ships both ESM(8.6MB) and CJS. And we only use CJS.

@dummdidumm
Copy link
Member

That's a nice idea which is low-effort and can be done directly without introducing a build step (which we may want later, but not right now) - would you like to test this out and create a PR for it?

dummdidumm pushed a commit that referenced this issue Dec 14, 2021
#139

- Ignore some different purpose builds for typescript. We didn't use them.
- Ignore typescript localization. We didn't enable localized diagnostic.
- Ignore large ESM files, We're currently using common js

Brings the size down from 105MB to 42MB.
About typescript localization, it's possible to enable this. So if we want to enable it in the future, we can unignore these files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants