GithubHelp home page GithubHelp logo

ljbc1994 / inject-html-webpack-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ali322/inject-html-webpack-plugin

1.0 2.0 0.0 53 KB

inject script label and style links into your html

HTML 7.27% JavaScript 91.41% CSS 1.32%

inject-html-webpack-plugin's Introduction

inject-html-webpack-plugin Build Status npm version

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'],
            processor:"http://cdn.example.com",
            customInject:[{
                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 files,accept string to prepended or function that receive file path and return url string
  • filename: html file path which injected
  • chunks: injected array of chunks
  • startInjectJS: start indentifier where to inject script labels,(eg: )
  • endInjectJS: end indentifier where to inject script labels,(eg: )
  • startInjectCSS: start indentifier where to inject style links,(eg: )
  • endInjectCSS: end indentifier where to inject style links,(eg: )
  • customInject: 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

inject-html-webpack-plugin's People

Contributors

ali322 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.