Webpack: How do I bundle multiple javascript files into a single output file?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 13:27:47

问题


Suppose I have two files, main.js and app.js; how do I use Webpack to bundle both of them into one file: bundle.js?


回答1:


create one entry.js which is your webpack entry file and in this your require your additional files

webpack.config.js

module.exports = {
   entry: './src/entry.js'
   ...
};

/src/entry.js

require('./main.js');
require('./app.js');

if these two files depend on each other, it would be be beneficial to reflect this in your dependency tree and require main.js in your app.js and not in entry.js for example




回答2:


You can use webpack-concat-plugin.

https://www.npmjs.com/package/webpack-concat-plugin#publicpath-stringboolean-default-webpacks-publicpath



来源:https://stackoverflow.com/questions/45097737/webpack-how-do-i-bundle-multiple-javascript-files-into-a-single-output-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!