In my current project, I am utilizing babel for transpiling to ES5 and webpack for bundling the code. Babel adds specific functions at the beginning of each file to support various features, such as rest parameters here and import
statements here.
For instance, almost every file contains this declaration:
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
Additionally, some files include the following:
var _toConsumableArray = function (arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } };
In a smaller personal project, this setup is manageable. However, in my larger work project, I believe I can optimize by consolidating all these polyfills into one centralized location that babel/webpack can reference. Instead of including _interopRequire
in every file with imports, I aim to have it in a single place for reference.
Is there a way to achieve this optimization?