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

Bundle size reduction #960

Closed
advzr opened this issue Mar 9, 2017 · 5 comments
Closed

Bundle size reduction #960

advzr opened this issue Mar 9, 2017 · 5 comments

Comments

@advzr
Copy link

advzr commented Mar 9, 2017

Hello. First of all I would like to thank you for your work on the project. It makes a lot easier to communicate with backend.
Recently we started to use swagger-js for our widget service and what bothers me is the overall bundle size. Our service is installed on other websites that already have their own code, so every Kb counts. As far as I can see the big size is mainly because of these lib dependencies:

  1. js-yaml
    I understand that most probably this library is included to have universal code for browsers and node. But for those who use swagger-js only as a browser client that is 44Kb (according to webpack bundle analyser plugin) of unused gzipped code. That is greater than jQuery with its 30Kb.
  2. lodash-compat
    This version of lodash is discontinued, and if I already have lodash or lodash-es, I end up with 2 versions of the same library.
  3. q
    As for q there is already an issue where it is confirmed that there will be an opportunity to use own promise lib. That is great to hear.

It would be great if swagger-js started to use es6 modules. Then we could import different versions of swagger-js. Those who need the lib for universal code could import swagger with js-yaml, while others would take a version without it. Or maybe there could be another npm package swagger-js-es just like lodash does for those who want swagger-js with lodash-es and promises from babel-polyfill for size reduction.

@webron
Copy link
Contributor

webron commented Mar 9, 2017

@advzr - thanks for the note. We are very close to releasing a brand new version of this library which handles almost everything you mention here. Our main dependency that remains here is still js-yaml but we're looking into alternatives now as we're trying to minimize the bundle size. We have a few thoughts about it, so hopefully it'll work out.

@strongui
Copy link

strongui commented Apr 8, 2017

This needs to be a much higher priority, the size of this library is insanely large for what it provides.

@webron
Copy link
Contributor

webron commented Apr 8, 2017

The current 3.X version is significantly smaller than 2.X. There's one dependency we're looking to see if we can replace, but it's not high on our priorities. As always, contributions are welcome.

@webron webron closed this as completed Apr 8, 2017
@strongui
Copy link

strongui commented Apr 8, 2017

Without this issue resolved, migrating to 3.0 is not an option.

@a-ignatov-parc
Copy link

There is a way to get rid of js-yaml with webpack and it's alias feature.

All you need to do is to mock safeLoad method like this:

// mock/js-yaml.js
export function safeLoad(body) {
  return JSON.parse(body);
}

And add alias to webpack's config:

{
  alias: {
    'js-yaml': path.resolve('./mock/js-yaml'),
  },
}

And there you go! Bundle size now weighs ~200kb less.

The only prerequisite to this workaround is to use only json spec or otherwise you may end up with parsing errors.

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