Skip to content

hipstersmoothie/html-webpack-insert-text-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

html-webpack-insert-text-plugin

code style: prettier CircleCI npm npm

Insert text into the head or body of your HTML

Installation

You must be running webpack 4.

npm install --save-dev html-webpack-insert-text-plugin

Usage

Require the plugin in your webpack config

import HtmlWebpackInsertPlugin from 'html-webpack-insert-text-plugin';
// or
const HtmlWebpackInsertPlugin = require('html-webpack-insert-text-plugin')
  .default;

Add the plugin to your webpack config as follows

plugins: [
  new HtmlWebpackPlugin(),
  new HtmlWebpackInjectPlugin([
    {
      target: 'index.html',
      parent: 'head',
      text: 'body { background: red; }'
    },
    {
      target: 'index.html',
      parent: 'body',
      text: '<script>alert('foo')</script>'
    }
  ])
];

Structure

html-webpack-insert-text-plugin takes an array of configuration objects. Those object should have the following structure.

  • target (optional): name of HTML page to target
  • parent: parent element to add into, only can be head or body, default value is head
  • text: text to insert into the parent

About

Insert text into the head or body of your HTML

Resources

License

Stars

Watchers

Forks

Packages

No packages published