Skip to content

fizix-io/html-webpack-inject-attributes-plugin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

add custom attributes to inject tags

install

   npm install html-webpack-inject-attributes-plugin

use

please use it after html-webpack-plugin, especially in webpack2+.

add to all inject tags

    plugins = [
        new htmlWebpackInjectAttributesPlugin({
            inject: "true",
            async: true,
            test: {}
        })  // Object, key should be string, value can be string or function
    ]

you got

    <script type="text/javascript" src="index.js" inject="true" async test="{}"></script>

add to chunks in HtmlWebpackPlugin by add attributes to HtmlWebpackPlugin

    plugins = [
        new HtmlWebpackPlugin({
            inject: true,
            hash: true,
            chunks: ['index'],
            attributes: {
                'data-src': function (tag) { return tag.attributes.src }
            },
        })  // Object, key and value should be string
    ]
    /**
     *  if value is a function, got three arguments。
     *  1、tag, ast of tag node
     *  2、compilation, you can get webpack build hash by compilation.hash
     *  3、index, index of trunks
    **/

you got

    <script type="text/javascript" src="index.js" data-src="index.js" inject="true"></script>

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%