Webpack with an array provided as config

2020-05-24 19:59发布

In this webpack starter kit https://github.com/webpack/react-starter I see the webpack.production.config.js module does not export only a config object but an array of config objects instead:

module.exports = [
    require("./make-webpack-config")({
        // commonsChunk: true,
        longTermCaching: true,
        separateStylesheet: true,
        minimize: true
        // devtool: "source-map"
    }),
    require("./make-webpack-config")({
        prerender: true
    })
];

What will happen in this case, when multiple config objects are provided? It isn't mentioned in webpack's docs

标签: webpack
2条回答
够拽才男人
2楼-- · 2020-05-24 20:50

Can be used to produce two different outputs - otherwise undoable in Webpack (AFAIK).

Eg: Produce full Production-ready output config into wwwroot directory in an ASP.Net Server-side web app, so that you can run and test everything by running the ASP.Net app on IIS, in Visual Studio WHILE SIMULTANEOUSLY Produce a simple HTML page (with HtmlWebpackPlugin) into your_app/dist folder, so you can run just the JS app and on Webpack DevServer and edit the JS app, in VSCode

Two people could work side by side on the same project, at the same time, the way John Lennon Imagined...

查看更多
爷、活的狠高调
3楼-- · 2020-05-24 20:58

Passing an array enables Webpack's multi-compiler mode. It's just a way to run Webpack multiple times in one pass. For instance, if you're making a Chrome & Firefox extension, you could use the multi-compiler to create both at once.

Webpack Multi-compiler example using mobile/desktop bundles.

查看更多
登录 后发表回答