html-add-attr-webpack-plugin

1.0.1 • Public • Published

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

Package Sidebar

Install

npm i html-add-attr-webpack-plugin

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

2.8 kB

Total Files

4

Last publish

Collaborators

  • anothersola