-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
三少
committed
Aug 9, 2022
1 parent
b3b0a17
commit f88ce60
Showing
7 changed files
with
504 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
*.log | ||
*.swp | ||
|
||
.github | ||
.cache | ||
.temp | ||
.idea | ||
.rn_temp | ||
.DS_Store | ||
|
||
CHANGELOG.md | ||
package-lock.json | ||
|
||
src | ||
node_modules | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# @antmjs/plugin-global-fix | ||
|
||
> 解决Taro使用polyfill的时候支付宝等小程序报错的问题 | ||
## 为什么需要 | ||
|
||
解决Taro使用polyfill的时候支付宝等小程序报错的问题 | ||
|
||
## 安装 | ||
|
||
```bash | ||
yarn add @antmjs/plugin-global-fix --dev | ||
``` | ||
|
||
## 使用 | ||
|
||
config/index.js | ||
|
||
```javascript | ||
const GlobalFixPlugin = require('@antmjs/plugin-global-fix') | ||
{ | ||
mini: { | ||
webpackChain(chain) { | ||
chain | ||
.plugin('GlobalFixPlugin') | ||
.use(new GlobalFixPlugin()) | ||
}, | ||
} | ||
} | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const PLUGIN_NAME = 'GlobalFixPlugin' | ||
function GlobalFixPlugin(options) { | ||
this.options = options | ||
} | ||
|
||
// 在插件函数的 prototype 上定义一个 `apply` 方法。 | ||
GlobalFixPlugin.prototype.apply = function (compiler) { | ||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => { | ||
compilation.hooks.processAssets.tap( | ||
{ | ||
name: PLUGIN_NAME, | ||
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS, | ||
}, | ||
(assets) => { | ||
for (const asset in assets) { | ||
if ( | ||
/runtime\.js$/.test(asset) && | ||
(process.env.TARO_ENV === 'kwai' || | ||
process.env.TARO_ENV === 'alipay' || | ||
process.env.TARO_ENV === 'dd' || | ||
process.env.TARO_ENV === 'swan') | ||
) { | ||
compilation.updateAsset(asset, (source) => { | ||
return new sources.RawSource( | ||
source | ||
.source() | ||
.replace( | ||
"return this || new Function('return this')();", | ||
'return {Object,Function,Array,Number,parseFloat,parseInt,Infinity,NaN,Boolean,String,Symbol,Date,Promise,RegExp,RangeError,ReferenceError,SyntaxError,TypeError,URIError,JSON,Math,console,Intl,ArrayBuffer,Uint8Array,Int8Array,Uint16Array,Int16Array,Uint32Array,Int32Array,Float32Array,Float64Array,Uint8ClampedArray,DataView,Map,Set,WeakMap,WeakSet,Proxy,Reflect,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,escape,unescape,isFinite,isNaN,clearInterval,setInterval};', | ||
), | ||
) | ||
}) | ||
} | ||
} | ||
}, | ||
) | ||
}) | ||
} | ||
module.exports = GlobalFixPlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"name": "@antmjs/plugin-global-fix", | ||
"version": "1.19.2", | ||
"main": "index.js", | ||
"author": "三少 <hi_sanshao@outlook.com>", | ||
"description": "解决Taro使用polyfill的时候支付宝等小程序报错的问题", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org" | ||
}, | ||
"keywords": [ | ||
"小程序" | ||
], | ||
"repository": { | ||
"type": "https", | ||
"url": "https://github.com/AntmJS/antm.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/AntmJS/antm/issues/new" | ||
}, | ||
"engines": { | ||
"node": ">=12", | ||
"npm": ">=6.4", | ||
"yarn": ">=1.22" | ||
}, | ||
"browserslist": [ | ||
"Chrome >= 35", | ||
"ChromeAndroid >= 35", | ||
"iOS >= 8", | ||
"Safari >= 8", | ||
"Android >= 4.1", | ||
"QQAndroid >= 4.1", | ||
"UCAndroid >= 4.1" | ||
], | ||
"scripts": { | ||
"build": "", | ||
"test:watch": "", | ||
"test": "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# @antmjs/mini-fix | ||
# @antmjs/plugin-mini-fix | ||
|
||
> 解决Taro不应该关心但应用需要自己处理的异常或者优化 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.