webpack_script_cross
v1.0.15
Published
📦 Add the crossorigin attribute to HTML scripts(CORS), support webpack v4 | 为 HTML 脚本添加 crossorigin 属性(跨域支持),支持 webpack v4
Downloads
3
Readme
webpack_script_cross
English | 简体中文
✨ Features
- Zero-config, easy to use
- Support webpack v4/5
- Support html-webpack-plugin v4/5
- 零配置/极简使用
- 支持 webpack 版本 v4/5
- 支持 html-webpack-plugin 版本 v4/5
🚀 QuickStart
Install
npm i webpack_script_cross -D
Usage
Please put it after
HtmlWebpackPlugin
const WebpackScriptCross = require('webpack_script_cross')
const webpackConfig = {
/* ... */
plugins: [
new HtmlWebpackPlugin(), // inject must be true (by default)
new WebpackScriptCross(),
],
/* ... */
output:{
/* ... */
crossOriginLoading:"anonymous" // Spa should have this to add (crossorigin) to script tag dynamically.
// crossOriginLoading:"anonymous" only works when script.src is different from site's origin
/* ... */
}
}
Attention: if this not working in react project, please ensure the version of react-scripts >= "^4.0.1"
Config
Default config:
{ crossorigin: 'anonymous',debug:false }
new WebpackScriptCross({
crossorigin: 'anonymous', // optional
debug:false // optional
})
Changelog
License
Copyright (c) 2020-present, yangshan.andy