A HTML Webpack Plugin that injects a custom string into the body of the html-webpack-plugin output.It is compatible with different versions of WebPack and HtmlWebPackPlugin. (inspired by inject-body-webpack-plugin)
- It is compatible with different versions of WebPack and HtmlWebPackPlugin.
- It can work according to process.env.NODE_ENV.
npm i -D inject-body-compaticity-webpack-plugin
webpack.config.js
import HtmlWebpackPlugin from "html-webpack-plugin"
import InjectBodyCompaticityWebpackPlugin from "inject-body-compaticity-webpack-plugin"
export default {
mode: 'development',
plugins: [
new HtmlWebpackPlugin(),
new InjectBodyCompaticityWebpackPlugin({
position:'start',
content: '<script>alert("Hello InjectBodyCompaticityWebpackPlugin!")</script>',
env: ["development"]
}),
],
}
index.html
<html><body><script>alert("Hello InjectBodyCompaticityWebpackPlugin!")</script></body></html>
Type | Default | Info | |
---|---|---|---|
position | string | start | If “start”, the content will be injected as close to the body opening tag as possible. If “end”, the content will be injected as close to the body ending tag as possible. |
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 |