env-inject-body-webpack-plugin

Webpack plugin that injects a custom string into the end of the body of html-webpack-plugin output according to the environment.

Usage no npm install needed!

<script type="module">
  import envInjectBodyWebpackPlugin from 'https://cdn.skypack.dev/env-inject-body-webpack-plugin';
</script>

README

env-inject-body-webpack-plugin

A HTML Webpack Plugin for injecting a custom string into the end of body of html-webpack-plugin output according to the environment. (inspired by inject-body-webpack-plugin)

Installation

npm i -D env-inject-body-webpack-plugin

Example

Input

webpack.config.js

import HtmlWebpackPlugin from "html-webpack-plugin"
import InjectBodyPlugin from "env-inject-body-webpack-plugin"

export default {
  mode: 'development',
  plugins: [
    new HtmlWebpackPlugin(),
    new InjectBodyPlugin({
      content: '<script src="index.js"></script>',
      env: ["development"]
    }),
  ],
}

Output

index.html

<html><body><script src="index.js"></script></body></html>

Options

Type Default Info
content string "" The text that will be injected into the final HTML output.
env string[] [] When the value of process.env.NODE_ENV is in the list, the plugin will take effect