Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPM VersionDependency StatusBuild StatusDownload StatusMIT License

add custom attributes to inject tags

install

npminstallhtml-webpack-inject-attributes-plugin-D

use

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

add to all inject tags, effective in all html

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>

return false to prevent some tags add attributes

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

use chainWebpack

// 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'}])},}

LICENSE

MIT License

About

Easy and powerful way to add ext attributes to tag with html-webpack-plugin

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp