Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack with an array provided as config

Tags:

webpack

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

like image 697
KwiZ Avatar asked Apr 15 '15 03:04

KwiZ


People also ask

What is a webpack config?

Webpack configs allow you to configure and extend Webpack's basic functionality. A Webpack config is a JavaScript object that configures one of Webpack's options. Most projects define their Webpack config in a top-level webpack. config. js file, although you can also pass the config as a parameter to Webpack's Node.

Where do I put webpack config?

The easiest way to get your webpack. config. js file to work is to place it at the top level of your project's folder structure along with your package. json file.

What is the format of webpack config file?

You may have noticed that few webpack configurations look exactly alike. This is because webpack's configuration file is a JavaScript file that exports a webpack configuration. This configuration is then processed by webpack based upon its defined properties.

Is it mandatory to use a configuration file when setting up a webpack project?

Out of the box, webpack won't require you to use a configuration file. However, it will assume the entry point of your project is src/index. js and will output the result in dist/main.


Video Answer


2 Answers

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.

like image 185
matpie Avatar answered Oct 11 '22 00:10

matpie


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...

like image 1
Shane Avatar answered Oct 10 '22 23:10

Shane