Install
npm i --save-dev html-webpack-static-assets-plugin
yarn add --dev html-webpack-static-assets-plugin
This is an extenstion of HtmlWebpackPlugin (version 4+ required!) that allows you to extend a list of tags (head and body) created by HtmlWebpackPlugin. This plugin needs to be added after HtmlWebpackPlugin.
F.E preload fonts with a hashes in filename.
webpack.config.js
const HtmlWebpackPlugin = const HtmlWebpackStaticAssetsPlugin = ; moduleexports = ... // Other options plugins: HtmlWebpackPlugin headTags: test: /\.woff/ tagName: "link" rel: "preload" as: "font" type: "font/[.ext]" crossorigin: true
This will generate a file index.html
:
Webpack App
Options
name | type | Default | Description |
---|---|---|---|
bodyTags | array | [] | A list of tags to be added to the body tag |
headTags | array | [] | A list of tags to be added to the head tag |
Single Tag Options
This is just overview. You are able to add any type of tag attribute.
name | type | Required | Description |
---|---|---|---|
test | RegExp | yes | RegExp to search for a files |
tagName | String | yes | The name of the tag to be created |
rel | String | no | "rel" attribute |
as | String | no | "as" attribute |
type | String | no | "type" attribute ([.ext] will be converted to a file extension) |
crossorigin | Boolean | no | "crossorigin" attribute |