The plugin writes CSS and JS asset paths for you automatically. It works with webpack 4 or higher.
It does not work with html-webpack-plugin plugins!
Usagenpm install mini-html-webpack-plugin
Multiple pagesconst { MiniHtmlWebpackPlugin } = require('mini-html-webpack-plugin');
Â
const config = {
  plugins: [
    new MiniHtmlWebpackPlugin({
     Â
      filename: 'demo.html',
     Â
      publicPath: 'demo/',
      context: {
        title: 'Webpack demo',
       Â
        htmlAttributes: {
          lang: 'en'
        },
       Â
        head: '',
       Â
        body: '',
       Â
        cssAttributes: {
          rel: 'preload',
          as: 'style'
        },
       Â
        jsAttributes: {
          defer: true
        }
      },
     Â
     Â
      chunks: ['app']
    })
  ]
};
It's possible to use MiniHtmlWebpackPlugin
to develop sites with multiple pages. It can be combined with webpack's bundle splitting so you can share common code across different pages.
To achieve this, you'll have to define entry
against each the code for each page and define MiniHtmlWebpackPlugin
to match them. In practice you might want to abstract this pairing but to give you the full idea, consider the example below.
HTML minificationconst { MiniHtmlWebpackPlugin } = require('mini-html-webpack-plugin');
Â
const config = {
  entry: {
    app: './app.js',
    another: './another.js'
  },
  plugins: [
    new MiniHtmlWebpackPlugin({
      filename: 'index.html',
      chunks: ['app'],
    }),
    new MiniHtmlWebpackPlugin({
      filename: 'another.html',
      chunks: ['another'],
    },
  ],
};
Custom templatesconst minify = require('html-minifier').minify;
const { MiniHtmlWebpackPlugin } = require('mini-html-webpack-plugin');
Â
const config = {
  plugins: [
    new MiniHtmlWebpackPlugin({
      context: {
        title: 'Minification demo'
      },
      template: (context) =>
        minify(MiniHtmlWebpackPlugin.defaultTemplate(context))
    })
  ]
};
Use @vxna/mini-html-webpack-template to add an app container div, a favicon, meta tags, inline JavaScript or CSS.
Or define a template function to generate your own code.
The template function may return a string or a Promise
resolving to a string.
Licenseconst {
  MiniHtmlWebpackPlugin,
  generateAttributes,
  generateCSSReferences,
  generateJSReferencesÂ
}Â =Â require('mini-html-webpack-plugin');
Â
const config = {
  plugins: [
    new MiniHtmlWebpackPlugin({
      filename: 'demo.html',
      publicPath: 'demo/',
     Â
      context: {
        title: 'Webpack demo',
        htmlAttributes: {
          lang: 'en'
        },
        cssAttributes: {
          rel: 'preload',
          as: 'style'
        },
        jsAttributes: {
          defer: true
        }
      },
      template: ({
        css,
        js,
        publicPath,
        title,
        htmlAttributes,
        cssAttributes,
        jsAttributes
      }) => {
        const htmlAttrs = generateAttributes(htmlAttributes);
Â
        const cssTags = generateCSSReferences({
          files: css,
          attributes: cssAttributes,
          publicPath
        });
Â
        const jsTags = generateJSReferences({
          files: js,
          attributes: jsAttributes,
          publicPath
        });
Â
        return `<!DOCTYPE html>
        <html${htmlAttrs}>
          <head>
            <meta charset="UTF-8">
            <title>${title}</title>
            ${cssTags}
          </head>
          <body>
            ${jsTags}
          </body>
        </html>`;
      }
    })
  ]
};
MIT.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4