01
Konfiguration
Einfache Konfiguration
Entry und output definieren das Bündeln.
webpack
module.exports = {
entry: "./src/index.js",
output: {
path: path.resolve("dist"),
filename: "bundle.js",
},
};Loaders
Loaders transformieren Nicht-JS-Module.
webpack
module: {
rules: [
{ test: /\.css$/, use: ["style-loader", "css-loader"] },
{ test: /\.ts$/, use: "ts-loader" },
],
}Plugins
Plugins erweitern die webpack-Funktionalität.
webpack
const HtmlWebpackPlugin = require("html-webpack-plugin");
plugins: [
new HtmlWebpackPlugin({ template: "./src/index.html" }),
]02
Optimierung
Code Splitting
Code in kleinere Chunks aufteilen.
webpack
optimization: {
splitChunks: {
chunks: "all",
},
}Dev Server
Entwicklungsserver mit HMR.
webpack
devServer: {
contentBase: "./dist",
hot: true,
port: 3000,
}Was this helpful?