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

Ship ES6 version of the library #33

Closed
stalniy opened this issue Mar 10, 2020 · 9 comments · Fixed by #36
Closed

Ship ES6 version of the library #33

stalniy opened this issue Mar 10, 2020 · 9 comments · Fixed by #36

Comments

@stalniy
Copy link
Contributor

stalniy commented Mar 10, 2020

Today there are major browsers support ES6 and ESM, so it make sense to ship ES6 version of your library together with UMD version.

Usually there are 3 types of versions which are good to have in your package:

  • ES6 + ESM (ES modules)
  • UMD
  • ES5 + ESM (es5m or esm5)

To make this job easier I'd recommend you to use rollup instead of webpack. The resulting bundle will be smaller and without internal module system (which webpack adds in the bundle).

You can check https://github.com/stalniy/rollup-plugin-content/blob/master/rollup.config.js to see how I did this in one of my libraries.

Let me know if you need help with this, I can submit a PR.

@lucaong
Copy link
Owner

lucaong commented Mar 10, 2020

Hi @stalniy
good point about the ES6 version. I also switched to Rollup on react-minisearch and it did reduce the bundle size and general complexity of the build, so I would be in favor of making the switch for MiniSearch too.

If you do have time to send a PR, it would be awesome. Otherwise, I will work on this as soon as I have the chance.

stalniy added a commit to stalniy/minisearch that referenced this issue Mar 27, 2020
This reduces final minified size on 2KB :)

Fixes lucaong#33
@stalniy
Copy link
Contributor Author

stalniy commented Mar 27, 2020

Hi @lucaong

Please check the PR and release a new version. With rollup mingzipped size is ~ 2 KB smaller :) and ~7KB smaller without gzip

Update: let me know if you have any questions

stalniy added a commit to stalniy/minisearch that referenced this issue Mar 27, 2020
This reduces final minified size on 2KB :)

Fixes lucaong#33
@lucaong
Copy link
Owner

lucaong commented Mar 27, 2020

Amazing! Thanks a lot, I'll check it now.

lucaong pushed a commit that referenced this issue Mar 27, 2020
This reduces final minified size on 2KB :)

Fixes #33
@lucaong
Copy link
Owner

lucaong commented Mar 27, 2020

I released a new version v2.2.0. The build is indeed noticeably smaller: https://bundlephobia.com/result?p=minisearch@2.2.0

Thanks again!

@stalniy
Copy link
Contributor Author

stalniy commented Mar 27, 2020

If you publish minified version, you will be able to save additional 1KB. I used terser to minify the bundle. Terser allows to mangle properties. That means that all private properties that start from _ will be replaced with a single character! It's ok to make code unreadable, sourcemaps will allow to debug it in both nodejs and browser.

@stalniy
Copy link
Contributor Author

stalniy commented Mar 27, 2020

Please also add "sideEffects": false, to your package.json, more info in https://webpack.js.org/guides/tree-shaking/#mark-the-file-as-side-effect-free

@lucaong
Copy link
Owner

lucaong commented Mar 28, 2020

Hi @stalniy , good point, I will add "sideEffects": false to the package.json to allow for tree shaking, and release a patch version. As for the minification, it was discussed in #4 that minification should be the responsibility of the application using the library.

@stalniy
Copy link
Contributor Author

stalniy commented Mar 28, 2020

@lucaong I don't agree with the comment of the issue #4 . Because

  1. it's not always possible to mangle the whole application.
    Some libraries which the app use may not support this, to make sure that the property mangling works correctly with 3rd party library, you need to dig deep into its source code. Nowadays nobody runs tests on built code, everybody uses jest and jest compile source code according to own rules. So, the issues with the minification can be found only in production (in case if 3rd party works incorrectly with property mangling enabled). Usually nobody cares. On the other hand, library authors can easily garantee this in the scope of library.
  2. People should use sourcemaps for debugging, then everything is ok

Anyway, nobody fights for extra 1KB, so it's up to you.

@lucaong
Copy link
Owner

lucaong commented Mar 28, 2020

I see your point. I will take some time to think about it, and check what other libraries are doing before deciding on this.

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

Successfully merging a pull request may close this issue.

2 participants