add custom attribute support for preload/prefetch by moyus · Pull Request #53 · numical/script-ext-html-webpack-plugin
When maintain a large web application, we need to deploy static assets on CDN, which has a different origin against our web domain. So in order to use tools like sentry to track js errors, we need to add crossorigin="anonymous" attribute on scripts.
However, when use preload/prefetch feature of script-ext-html-webpack-plugin, the output <link /> don't contain crossorigin="anonymous", which will cause double fetches.
<link ref="preload" as="script" href="//a-cdn-server.com/some-script.js" />
...
<script src="//a-cdn-server.com/some-script.js" crossorigin="anonymous"></script>
This PR is try to add a feature to support custom attributes for link tag.
example:
plugins: [
new HtmlWebpackPlugin(),
new ScriptExtHtmlWebpackPlugin({
custom: {
test: /\.js$/,
attribute: 'crossorigin',
value: 'anonymous'
},
preload: {
test: /\.js$/,
attrs: {
crossorigin: 'anonymous'
}
}
})
]