babel-polyfills
babel-polyfills copied to clipboard
When I use polyfill-es-shims plugin on my code it tries to import nodeJS `util.inspect` which requires rollup-plugin-polyfill-node...
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,
})
);
Can you give an example of code that is unnecessary?
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?
a lot of the code is indeed necessary for polyfilling Array map correctly; util.inspect
, though, I wouldn't expect.