- Notifications
You must be signed in to change notification settings - Fork4
Easy and powerful way to add ext attributes to tag with html-webpack-plugin
License
NotificationsYou must be signed in to change notification settings
dyw934854565/html-webpack-inject-attributes-plugin
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
add custom attributes to inject tags
npminstallhtml-webpack-inject-attributes-plugin-D
please use it after
html-webpack-plugin
, especially in webpack2+.
plugins=[newHtmlWebpackPlugin(),newhtmlWebpackInjectAttributesPlugin({inject:"true",async:true,test:{}})// Object, key should be string, value can be string or function、object, object will stringify]
you got
<scripttype="text/javascript"src="index.js"inject="true"asynctest="{}"></script>
add to chunks in HtmlWebpackPlugin by add attributes to HtmlWebpackPlugin,only effective in the current html
plugins=[newHtmlWebpackPlugin({attributes:{'data-src':function(tag){returntag.attributes.src}},}),newhtmlWebpackInjectAttributesPlugin()]/** * 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
<scripttype="text/javascript"src="index.js"data-src="index.js"inject="true"></script>
plugins=[newHtmlWebpackPlugin({inject:true,hash:true,chunks:['index'],attributes:{'data-src':function(tag,compilation,index){if(tag.tagName==='script'){returntrue;}returnfalse;}},}),newhtmlWebpackInjectAttributesPlugin()]
style tags do not be affected
// vue.config.jsconsthtmlInject=require('html-webpack-inject-attributes-plugin')module.exports={chainWebpack:(config)=>{config.plugin('html').tap(args=>{args[0].attributes={async:true,inject:'true'}returnargs})config.plugin('html-inject').after('html').use(htmlInject,[{common:'true'}])},}
About
Easy and powerful way to add ext attributes to tag with html-webpack-plugin
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.