File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -78,10 +78,16 @@ const WorkerProxy = new Proxy<Worker>(originalWorker, {
7878 }
7979
8080 if ( url && ! isSameOrigin ( url ) ) {
81+ let workerPath = scriptURL
8182 // 如果 scriptURL 是跨域的,使用 Blob URL 加载并执行 worker
82- const script = `import "${ scriptURL } ";`
83- const workerPath = urlFromScript ( script )
84- options . type = 'module'
83+ // 应该遵总 worker 的 type 类型。classic worker
84+ if ( options . type === 'module' ) {
85+ const script = `import "${ scriptURL } ";`
86+ workerPath = urlFromScript ( script )
87+ } else {
88+ const script = `importScripts("${ scriptURL } ");`
89+ workerPath = urlFromScript ( script )
90+ }
8591 return new Target ( workerPath , options ) as WorkerInstance
8692 } else {
8793 // 如果 scriptURL 是同源的,直接使用原生的 Worker 构造函数
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import {
2626import {
2727 appInstanceMap ,
2828} from '../../create_app'
29+ import WorkerProxy from '../../proxies/worker'
2930
3031/**
3132 * patch window of child app
@@ -87,9 +88,18 @@ function createProxyWindow (
8788 const rawWindow = globalEnv . rawWindow
8889 const descriptorTargetMap = new Map < PropertyKey , 'target' | 'rawWindow' > ( )
8990
91+ Object . defineProperty ( microAppWindow , 'Worker' , {
92+ value : WorkerProxy ,
93+ configurable : true ,
94+ writable : true ,
95+ } )
96+
9097 const proxyWindow = new Proxy ( microAppWindow , {
9198 get : ( target : microAppWindowType , key : PropertyKey ) : unknown => {
9299 throttleDeferForSetAppName ( appName )
100+ if ( key === 'Worker' ) {
101+ return WorkerProxy
102+ }
93103 if (
94104 Reflect . has ( target , key ) ||
95105 ( isString ( key ) && / ^ _ _ M I C R O _ A P P _ / . test ( key ) ) ||
You can’t perform that action at this time.
0 commit comments