1.0.1 • Published 3 years ago

inject-html-webpack-plugin v1.0.1

Weekly downloads
2,488
License
MIT
Repository
github
Last release
3 years ago

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

1.0.1

3 years ago

1.0.0

4 years ago

0.0.39

6 years ago

0.0.38

6 years ago

0.0.37

6 years ago

0.0.36

6 years ago

0.0.35

6 years ago

0.0.33

6 years ago

0.0.32

6 years ago

0.0.31

7 years ago

0.0.30

7 years ago

0.0.29

7 years ago

0.0.28

7 years ago

0.0.27

7 years ago

0.0.26

7 years ago

0.0.25

7 years ago

0.0.24

7 years ago

0.0.23

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

7 years ago

0.0.12

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago