简体   繁体   中英

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM