Adapt webpack 4: add custom attributes to inject script and link
npm install html-webpack-plugin-crossorigin#HTML Webpack Plugin Cross Origin (Webpack 4)
This plugin adapt html-webpack-inject-attributes-plugin(v1.0.0) for webpack 4.
``bash`
npm i --save-dev html-webpack-plugin-crossorigin`
##Usagejavascript
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackPluginCrossorigin = require('html-webpack-plugin-crossorigin');
new HtmlWebpackPlugin({
plugins: [
new HtmlWebpackPlugin({
filename: 'test.html',
template: 'src/assets/test.html'
// add script attributes here!
attributes: {
crossorigin: 'anonymous'
}
}),
// this one should be placed after HtmlWebpackPlugin
new HtmlWebpackPluginCrossorigin({
inject: true
})
]
});
`crossorigin=anonymous
It will add the to script tag like:`html``
This plugin fixed the problem from the origin one:
> ERROR in TypeError: callback is not a function
>
> - index.js:35
> [ex-child-webpack]/[html-webpack-inject-attributes-plugin]/index.js:35:13