I have 2 javascript files. How to bundle them into one file and enclose all code in one enclosed scope?

Say i have 2 files helpers.js index.js

Loading helpers.js will create global variables. I don't want that

I want one file.js that looks like

(function () {
    helpers.js code
    index.js code
})();
  1. Is this even possible?
  2. Can I do it with .NET Core Bundle And Minify?

1 answer

  • answered 2020-01-17 04:06 Sohail

    You can use webpack to bundle the js code.

    Or just use ES6 modules to modularize your code.

    Note: Not all browsers support ES6 modules. For that you need babel.

    Please refer this answer. I have explain this in detail .