1. inject-html-webpack-plugin
inject html when webpack compiling
inject-html-webpack-plugin
Package: inject-html-webpack-plugin
Created by: ali322
Last modified: Sun, 19 Jun 2022 01:18:48 GMT
Version: 1.0.1
License: MIT
Downloads: 9,478
Repository: https://github.com/ali322/inject-html-webpack-plugin

Install

npm install inject-html-webpack-plugin
yarn add inject-html-webpack-plugin

inject-html-webpack-plugin
Build Status

NPM

inspired by html-webpack-plugin,simple and efficient Webpack plugin that inject script label and style links into your html

Install

 npm install inject-html-webpack-plugin --save--dev

Usage

add plugin in your webpack.config.js

 var InjectHtmlPlugin = require('inject-html-webpack-plugin')

module.exports = {
    entry:{
        index:"./index.js"
    },
    module:{
        loaders:[
            ...
        ]
    },
    output:{
        path:'./dist',
        filename:'[name].min.js'
    },
    plugins:[
        new InjectHtmlPlugin({
            filename:'./index.html',
            chunks:['index'],
            transducer:"http://cdn.example.com",
            custom:[{
                start:'<!-- start:bundle-time -->',
                end:'<!-- end:bundle-time -->',
                content:Date.now()
            }]
        })
    ]
}

then add below placeholders into html file

 <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <!-- start:css -->
  <!-- end:css -->
  <!-- start:bundle-time -->
  <!-- end:bundle-time -->
</head>
<body>
  <!-- start:js -->
  <!-- end:js -->
</body>
</html>

Plugin Options

  • transducer: apply transducer to injected file's url,accept prepended string or function that receive file path as argument and return url string as result
  • filename: html file path which injected
  • chunks: injected array of chunks
  • jsLabelTemplate: use function to generate js Label
  • cssLabelTemplate: use function to generate css Label
  • startJS: start indentifier where to inject script labels,(eg: <!-- start:js -->)
  • endJS: end indentifier where to inject script labels,(eg: <!-- end:js -->)
  • startCSS: start indentifier where to inject style links,(eg: <!-- start:css -->)
  • endCSS: end indentifier where to inject style links,(eg: <!-- end:css -->)
  • custom: array of custom inject,like bundle time,accept objects contains below key/values,
    • start: inject start identifier
    • end: inject end identifier
    • content: injected content

License

MIT License

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin