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

When I use polyfill-es-shims plugin on my code it tries to import nodeJS util.inspect which requires rollup-plugin-polyfill-node... #205

Open
twilson90 opened this issue Feb 22, 2024 · 3 comments

Comments

@twilson90
Copy link

And adding 'rollup-plugin-polyfill-node' to my plugins adds a load of additional unnecessary code to the top of all my output files.

I struggle at the best of times to understand what I'm doing with babel and rollup, perhaps I'm doing something wrong.
This makes no sense.
Please help me out.

import { nodeResolve as rollup_node_resolve } from '@rollup/plugin-node-resolve';
import rollup_typescript from '@rollup/plugin-typescript';
import rollup_commonjs from '@rollup/plugin-commonjs';
...
  var plugins = [];
  plugins.push(
    rollup_typescript({
      "include": ["index.d.ts", "src/js/**/*.ts"],
      compilerOptions: {
        "module": "esnext",
        "target": "es6",
        "isolatedModules": true,
      }
    }),
    rollup_node_resolve(),
    rollup_commonjs(),
  );
  
  if (PRODUCTION) {
    var babel_presets = [];
    var babel_plugins = [];
    babel_plugins.push(["polyfill-es-shims", { "method": "usage-global" }]);
    babel_presets.push(
      [
        "@babel/preset-env",
        {
          "useBuiltIns": "entry",
          "corejs": "3.22"
        }
      ]
    );
    plugins.push(
      rollup_babel({
        "extensions": [".js", ".ts"],
        "babelHelpers": "bundled",
        "presets": babel_presets,
        "plugins": babel_plugins,
      })
    );
@ljharb
Copy link
Member

ljharb commented Feb 22, 2024

Can you give an example of code that is unnecessary?

@twilson90
Copy link
Author

twilson90 commented Feb 22, 2024

If I don't use 'rollup-plugin-polyfill-node' and I process the following JS string:

console.log([].map); (20 bytes)

It produces this:
app.js.txt (111kb)

If I use 'rollup-plugin-polyfill-node' plugin I get this:

app.js.txt (192kb)

Is all of this code necessary to get a working polyfill of Array.map?
Why is it polyfilling Node's util.inspect?

@ljharb
Copy link
Member

ljharb commented Feb 22, 2024

a lot of the code is indeed necessary for polyfilling Array map correctly; util.inspect, though, I wouldn't expect.

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

2 participants