[英]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假设我有 2 个文件 helpers.js index.js
Loading helpers.js will create global variables.加载 helpers.js 将创建全局变量。 I don't want that
我不想那样
I want one file.js that looks like我想要一个看起来像的 file.js
(function () {
helpers.js code
index.js code
})();
You can use webpack to bundle the js code.您可以使用 webpack 来打包 js 代码。
Or just use ES6 modules to modularize your code.或者只是使用ES6 模块来模块化你的代码。
Note: Not all browsers support ES6 modules.
注意:并非所有浏览器都支持 ES6 模块。 For that you need
babel
.为此,您需要
babel
。
Please refer this answer.请参考这个答案。 I have explain this in detail .
我已经详细解释了这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.