[英]Webpack: How do I bundle multiple javascript files into a single output file?
Suppose I have two files, main.js and app.js ;假设我有两个文件, main.js和app.js ; how do I use Webpack to bundle both of them into one file: bundle.js ?
我如何使用 Webpack 将它们捆绑到一个文件中: bundle.js ?
create one entry.js
which is your webpack entry file and in this your require
your additional files创建一个
entry.js
这是你的 webpack 入口文件,在这个你require
你的额外文件
webpack.config.js webpack.config.js
module.exports = {
entry: './src/entry.js'
...
};
/src/entry.js /src/entry.js
// new syntax
import './main.js';
import './app.js';
// or old syntax
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如果这两个文件相互依赖,那么在您的依赖树中反映这一点并在您的
app.js
中而不是在main.js
中需要 main.js 将是entry.js
的
You can pass an array of entries:您可以传递一组条目:
module.exports = {
entry: ['./main.js', './app.js'],
...
};
Also, you can pass them as a CLI option :此外,您可以将它们作为CLI 选项传递:
webpack ./main.js ./app.js --config=webpack.config.js
You can use webpack-concat-plugin.你可以使用 webpack-concat-plugin。
https://www.npmjs.com/package/webpack-concat-plugin#publicpath-stringboolean-default-webpacks-publicpath https://www.npmjs.com/package/webpack-concat-plugin#publicpath-stringboolean-default-webpacks-publicpath
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.