npm.io
1.0.1 • Published 6 years ago

html-add-attr-webpack-plugin

Licence
MIT
Version
1.0.1
Deps
1
Size
3 kB
Vulns
0
Weekly
0
Stars
2

HtmlAddAttrWebpackPlugin

Usage

Install

npm install html-add-attr-webpack-plugin -D
Example

for SPA (single-page-application):

//webpack.config.js
module.exports = {
  plugin: [
    //...other options
    new HtmlAddAttrWebpackPlugin({
      attrs: {
        'script': {
          crossOrigin: 'anonymous'
        }
      }
    })
  ]
}//will add crossOrigin="anonymous" to script tag.

for multi-page application:

//webpack.config.js
module.exports = {
  plugin: [
    //...other options
    new HtmlAddAttrWebpackPlugin([{
      attrs: {
        'script': {
          crossOrigin: 'anonymous'
        }
      } //will rewrite index.html
    }, {
      sourceFile: 'sub.html',
      attrs: {
        'link': {
          class: 'link'
        },
        'script': {
          class: 'sub'
        }
      } //will rewrite sub.html
    }])
  ]
}
Options
props description
sourceFile the html file that needs to rewrite. (default 'index.html')
attrs just like html attributes

tks for using

Keywords