A webpack.config.js file is a Node.js module that exports one configuration object. Webpack uses it automatically when it sits in the project root, and the --config flag points to another file. Each top-level key controls one part of the build:
const path = require('path');
module.exports = {
mode: 'development', // or 'production'
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
// Loader configurations
]
},
plugins: [
// Plugin instances
],
devServer: {
// Dev server configuration
}
};
modeturns on webpack's built-in defaults for development or production.entryis the module where webpack starts building the dependency graph.outputsets the folder and file name of the bundles. The folder must be an absolute path, which is why the config callspath.resolve.module.ruleslists the loaders that transform files such as CSS or TypeScript.pluginsholds plugin instances that work on the whole build.devServerconfigureswebpack-dev-serverfor local development.
The file can also export a function that receives the CLI's env and argv, so one file can return a different config per environment.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓