Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[微信] 小程序在使用worker的时候和编译优化冲突 #5276

Open
waterbang opened this issue Dec 29, 2024 · 0 comments
Open

[微信] 小程序在使用worker的时候和编译优化冲突 #5276

waterbang opened this issue Dec 29, 2024 · 0 comments

Comments

@waterbang
Copy link

小程序在使用worker多线程的时候要求:

Worker 内代码只能 require 指定 Worker 路径内的文件,无法引用其它路径

但是uniapp编译的时候会优化打包文件导致抽离出公共代码,类似下面这样:

"use strict";var e=(e,i,r)=>new Promise(((t,s)=>{var o=e=>{try{a(r.next(e))}catch(i){s(i)}},n=e=>{try{a(r.throw(e))}catch(i){s(i)}},a=e=>e.done?t(e.value):Promise.resolve(e.value).then(o,n);a((r=r.apply(e,i)).next())}));const i=require("../../common/vendor.js"),

这样就会导致引用了外部的代码, 导致错误。

我当前在 vite.config.ts 配置想排除抽离代码:

   build: {
      rollupOptions: {
        output: {
          manualChunks(id) {
            console.log('id -> ', id)
            if (id.includes('WasmService')) {
              return null
            }
          }
        }
      }
    }

但是我的日志也是没有任何打印,并且 文档 没有提示。

我应该如何排除这个抽离代码?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant