1.0.1 • Published 4 years ago

html-add-attr-webpack-plugin v1.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

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

propsdescription
sourceFilethe html file that needs to rewrite. (default 'index.html')
attrsjust like html attributes

tks for using