2.0.0 • Published 4 years ago

@vxna/mini-html-webpack-template v2.0.0

Weekly downloads
115,073
License
MIT
Repository
github
Last release
4 years ago

@vxna/mini-html-webpack-template

Build Status npm

Template for mini-html-webpack-plugin that extends default features with useful subset of options

Warning

It does not work with html-webpack-plugin

Common usage

webpack.config.js

const MiniHtmlWebpackPlugin = require('mini-html-webpack-plugin')

module.exports = {
  plugins: [
    new MiniHtmlWebpackPlugin({
      context: {
        title: 'common-usage',
        favicon: 'https://assets-cdn.github.com/favicon.ico',
        container: 'root',
        trimWhitespace: true
      },
      template: require('@vxna/mini-html-webpack-template')
    })
  ]
}

Common options

NameTypeDefaultDescription
lang{String}undefinedSet document language
title{String}'sample-app'Set document title
favicon{String}undefinedSet document favicon
container{String}undefinedSet application mount point
trimWhitespace{Boolean}undefinedSafe document whitespace reduction

Extended usage

webpack.config.js

const MiniHtmlWebpackPlugin = require('mini-html-webpack-plugin')

module.exports = {
  plugins: [
    new MiniHtmlWebpackPlugin({
      context: {
        title: 'extended-usage',
        head: {
          meta: [
            {
              name: 'description',
              content: 'mini-html-webpack-template'
            }
          ]
        },
        body: {
          raw: '<div id="root"></div>'
        },
        attrs: {
          js: {
            async: '',
            type: 'text/javascript'
          }
        }
      },
      template: require('@vxna/mini-html-webpack-template')
    })
  ]
}

Extended options

NameTypeDefaultDescription
head.meta{Array}undefinedArray of objects with key + value pairs
head.links{Array}undefinedArray of objects with key + value pairs
head.scripts{Array}undefinedArray of objects with key + value pairs
head.raw{Array\|String}undefinedGenerates raw document markup
body.scripts{Array}undefinedArray of objects with key + value pairs
body.raw{Array\|String}undefinedGenerates raw document markup
attrs.js{Object}undefinedApplies html attributes to webpack output
attrs.css{Object}undefinedApplies html attributes to webpack output

Advanced minification

For custom needs html-minifier middleware and all of it's options could be used

webpack.config.js

const { minify } = require('html-minifier')
const MiniHtmlWebpackPlugin = require('mini-html-webpack-plugin')

module.exports = {
  plugins: [
    new MiniHtmlWebpackPlugin({
      context: {
        title: 'advanced-minification'
      },
      template: ctx =>
        minify(require('@vxna/mini-html-webpack-template')(ctx), {
          collapseWhitespace: true,
          minifyCSS: true,
          minifyJS: true
        })
    })
  ]
}

Complex security features

SRI is out of scope of this project and it's recommended to use html-webpack-plugin with it's ecosystem tools.

Inspired by

html-webpack-template

License

MIT (http://www.opensource.org/licenses/mit-license.php)