html-webpack-alter-plugin

0.0.5 • Public • Published

html-webpack-alter-plugin

A plugin can alter the template when using html-webpack-plugin.

Installation

 npm i --save-dev html-webpack-alter-plugin

Usage

const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackAlterPlugin = require('html-webpack-alter-plugin');

module.exports = {
  plugins: [
    new HtmlWebpackPlugin(),
    new HtmlWebpackAlterPlugin({
      position: 'head',
      content: [
        {
          type: 'script',
          data: 'window.__MY_GLOBAL__={ name: "xiao ming", age: 18 };',
        },
        {
          type: 'style',
          data: '.red-text { color: red; }',
        }
      ]
    }),
  ],
};

npm run build and you will get the html file like this:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>React App</title>
    <script type="text/javascript">window.__MY_GLOBAL__={name:"xiao ming",age:18}</script><style>.red-text{color:red}</style>
  </head>
  </head>
  <body>
  </body>
</html>

Options

option type value
position string 'head'/'body'
content array { type: 'script'/'style', data }

Package Sidebar

Install

npm i html-webpack-alter-plugin

Weekly Downloads

0

Version

0.0.5

License

ISC

Unpacked Size

4.32 kB

Total Files

3

Last publish

Collaborators

  • howaboutryze