CARVIEW |
Community
webpack
- Defaults
- Configuration
- optimization.splitChunks
- splitChunks.automaticNameDelimiter
- splitChunks.chunks
- splitChunks.maxAsyncRequests
- splitChunks.maxInitialRequests
- splitChunks.defaultSizeTypes
- splitChunks.minChunks
- splitChunks.hidePathInfo
- splitChunks.minSize
- splitChunks.minSizeReduction
- splitChunks.enforceSizeThreshold
- splitChunks.minRemainingSize
- splitChunks.layer
- splitChunks.maxSize
- splitChunks.maxAsyncSize
- splitChunks.maxInitialSize
- splitChunks.name
- splitChunks.usedExports
- splitChunks.cacheGroups
- Examples
webpack contrib
- Getting Started
- Options
- Examples
- Recommended
- Minimal example
- Named export for CSS Modules
- The publicPath option as function
- Advanced configuration example
- Hot Module Reloading (HMR)
- Minimizing For Production
- Using preloaded or inlined CSS
- Extracting all CSS in a single file
- Extracting CSS based on entry
- Filename Option as function
- Long Term Caching
- Remove Order Warnings
- Multiple Themes
- Media Query Plugin
- Hooks
- Contributing
- License
HtmlWebpackPlugin
The HtmlWebpackPlugin
simplifies creation of HTML files to serve your webpack bundles. This is especially useful for webpack bundles that include a hash in the filename which changes every compilation. You can either let the plugin generate an HTML file for you, supply your own template using lodash templates, or use your own loader.
Installation
npm install --save-dev html-webpack-plugin
Basic Usage
The plugin will generate an HTML5 file for you that includes all your webpack
bundles in the body using script
tags. Add the plugin to your webpack
configuration as follows:
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
module.exports = {
entry: 'index.js',
output: {
path: path.resolve(__dirname, './dist'),
filename: 'index_bundle.js',
},
plugins: [new HtmlWebpackPlugin()],
};
This will generate a file dist/index.html
containing the following:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>webpack App</title>
</head>
<body>
<script src="index_bundle.js"></script>
</body>
</html>
If you have multiple webpack entry points, they will all be included with <script>
tags in the generated HTML.
If you have any CSS assets in webpack's output (for example, CSS extracted with the MiniCssExtractPlugin) then these will be included with <link>
tags in the <head>
element of generated HTML.
Configuration
For all configuration options, please see the plugin documentation.
Third party addons
The plugin supports addons. For a list see the documentation.