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
})();
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.