Do no insert unnecessary setImmediate (solution for libraries)

Feature request

We need package.json option to disable webpack’s polyfills. Something like browser but for node options.

I am JS library author. I have this code in my library:

  if (typeof setImmediate !== 'undefined') {
  } else {
    setTimeout(action, 1);

Most of my users will use Webpack and it will insert unnecessary 2 KB polyfill.

What is the expected behavior?

I see two options:

  1. Do not insert setImmediate polyfill on typeof setImmediate !== 'undefined'wrap.
  2. Or read node config from library’s package.json

What is motivation or use case for adding/changing the behavior?

Performance is important.

How should this be implemented in your opinion?

Have no idea

Are you willing to work on this yourself?
I can try

Author: Fantashit

2 thoughts on “Do no insert unnecessary setImmediate (solution for libraries)

  1. We don’t have such option. Actually in my opinion library developers should not take care of polyfills. That’s a job for the application developer. They can decide if a polyfill is needed, but you can add a note to your documentation.

    But if you still want to opt-out. webpack only cares about free-vars. If you access the property from the global object it won’t include a polyfill:

      if (typeof global.setImmediate !== 'undefined') {
      } else {
        setTimeout(action, 1);

Comments are closed.