1.0.0 • Published 4 years ago

@forgleaner/webpack-html-inject-plugin v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

webpack-html-inject-plugin

build commitizen download npm semantic

A webpack plugin that inject some variables to entry html.

Usage

First, install webpack-html-inject-plugin as a development dependency:

npm i -D @forgleaner/webpack-html-inject-plugin

Then, add it to your webpack.config.js:

const HtmlInjectPlugin = require('webpack-html-inject-plugin');

webpackOptions.plugins.push(new HtmlInjectPlugin({
  filename: 'index.html',
  data: {
           ENV_DEBUG: false,
           ENV_DEV: true,
           token: 'zawQrZL963RGtXrd2rYmLmUOeckesAaLlYgtNVA89'
  }
}));

Before

<script>
  window.token = {{token}};
  window.ENV_DEBUG = {{ENV_DEBUG}};
  window.ENV_DEV = {{ENV_DEV}};
</script>

After

<script>
  window.ENV_DEBUG = false;
  window.ENV_DEV = true;
  window.token = 'zawQrZL963RGtXrd2rYmLmUOeckesAaLlYgtNVA89';
</script>

API

new HtmlInjectPlugin(options)

options

Type: object

filename

Type: String

The file to write the HTML to.
data

Type: object

Declara some variables to html.