DEV Community

Wojciech Maj
Wojciech Maj

Posted on • Updated on

Make your app install and run faster with nolyfill

Do you use eslint-plugin-import, eslint-plugin-jsx-a11y, eslint-plugin-react? Of course you do! What do they have in common? They all contain tons of polyfills to ensure backward compatibility. "With what?", you ask? With Node.js 4. NODE DOT JS VERSION FOUR. Released in 2015. "So?"

These polyfills are totally useless. Unless, of course, you run Node.js 4. They:

  • impact install times,
  • make your node_modules bigger,
  • and make your app run slower (native implementations are rarely slower than their polyfills).

So what can you do?

One way to deal with it is by forking such packages, stripping off useless dependencies, and re-releasing them under new names. This, however, is rarely worth it.

eslint-plugin-i

eslint-plugin-i, a fork of eslint-plugin-import, is a good example of when it IS worth it. Not only they do the above, but also replace tsconfig-paths and heavy typescript under the hood with get-tsconfig. This resolves security issues eslint-plugin-import has, vastly improves performance, and adds support for new TypeScript features. I highly recommend you replacing eslint-plugin-import with eslint-plugin-i, and if I'm not convincing enough, perhaps pure madness exhibited by eslint-plugin-import's lead maintainer in this issue will convince you to.

But usually, there's an easier way!

nolyfill

SukkaW created an amazing project called nolyfill. nolyfill is leveraging npm's, yarn's and pnpm's capabilities to replace heavy polyfills with so-called "nolyfills".

Nolyfills are tiny wrappers around what Node.js already offers. You must check it out!

https://github.com/SukkaW/nolyfill

Run npx nolyfill on your repo, and see for yourself, how many redundant dependencies you have!

@yarnpkg/plugin-nolyfill

On top of SukkaW's work, I've built another thing: @yarnpkg/plugin-nolyfill.It does the same thing nolyfill's CLI does, but hooks directly into Yarn resolution step, replacing the polyfills in question on the fly. It has the added benefit of "install and forget" - plugin will work every time you install your repository, so it guarantees no new redundant polyfills will ever appear in your repository.

If you use Yarn (2+), check it out as well!

Install it by running yarn plugin import https://raw.githubusercontent.com/wojtekmaj/yarn-plugin-nolyfill/v0.1.2/bundles/@yarnpkg/plugin-nolyfill.js. Then, reinstall repository by running yarn install.

Top comments (0)