dcloudio / dcloudio/uni-app

uniapp中,两个node_modules中的三方类库使用同一个另一个三方类库的变量,在小程序上为不同对象,而h5端为相同对象

Open
#4,411 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
41.6k
Forks
3.7k
Avg merge
7h 6m
Merged PRs (30d)
6

Description

不是说 esm是 引用变量么, 为什么在小程序上同一个模块导出的是两个不同的对象,就因为使用的项目不同?这两个项目都依赖了另一个项目,于是各新建了一个实体?

而在h5端,两个node_modules中的三方类库项目引用同一个第三方类库中到处的内容,是共享对象的

看小程序源码里面创建了两个这个对象

```

let SocialuniPluginsModule$1 = class SocialuniPluginsModule2 {
constructor() {
__publicField(this, "_router", null);
__publicField(this, "_route", null);
__publicField(this, "uid", UUIDUtil.getUUID());
__publicField(this, "socialuniPlugins", []);
console.trace("创建了socialplus");
}
get route() {
return this._route;
}
setRoute(value) {
this._route = value;
}
get router() {
return this._router;
}
setRouter(value) {
this._router = value;
}
init() {
this.socialuniPlugins = [];
}
addPlugin(...socialuniPlugins) {
this.socialuniPlugins.push(...socialuniPlugins);
}
get plugins() {
return this.socialuniPlugins;
}
};
const socialuniPluginsModule$1 = reactive(new SocialuniPluginsModule$1());
class SocialuniPluginsModule {
constructor() {
this._router = null;
this._route = null;
this.uid = UUIDUtil.getUUID();
this.socialuniPlugins = [];
console.trace("创建了socialplus");
}
get route() {
return this._route;
}
setRoute(value) {
this._route = value;
}
get router() {
return this._router;
}
setRouter(value) {
this._router = value;
}
init() {
this.socialuniPlugins = [];
}
addPlugin(...socialuniPlugins) {
this.socialuniPlugins.push(...socialuniPlugins);
}
get plugins() {
return this.socialuniPlugins;
}
}
const socialuniPluginsModule = reactive(new SocialuniPluginsModule());
```

源码

![d43ed9d82851ec571b05afa899d1c6e](https://github.com/dcloudio/uni-app/assets/14007972/c0375dc4-d020-4e85-bb78-1d6107458fec)

编译后

![1ae5aecb476b43539e6f49bc3f1bb3f](https://github.com/dcloudio/uni-app/assets/14007972/a0d58445-0f8a-4493-87f8-67d5a2e446f0)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.