Webpack builds a dependency graph from an entry point and emits it as output bundles, with loaders and plugins shaping the work in between. It is a static module bundler, which follows every import and require from the entry and combines the modules into bundles. The four main concepts:
entryis the module where webpack starts building the dependency graph,./src/index.jsby default.outputsets where and how to emit the bundles,./dist/main.jsby default.- Loaders, set in
module.rules, transform files from other languages and formats, such as CSS or TypeScript, into modules. pluginsextend webpack for wider tasks such as bundle optimization, asset management and injecting environment variables.
The docs list two more core concepts. mode turns on built-in defaults for development or production. The other is browser compatibility. The code webpack generates uses Promise for import(), so older browsers need a polyfill.
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [{ test: /\.js$/, use: 'babel-loader' }]
},
plugins: [new HtmlWebpackPlugin()]
};
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 ↓