Skip to content

🐛 [Bug]: 自定义组件库中引入 element plus,画布和 preview 无法正确渲染内嵌的 element plus 组件 #1594

Description

@jiahao-hub

Environment

None

Version

20

Version

2.7

Link to minimal reproduction

组件库复现样例:
https://github.com/jiahao-hub/demo-component-lib

Step to reproduce

准备组件库 CDN

  1. Clone 组件库

    git clone https://github.com/jiahao-hub/demo-component-lib
    
  2. 安装依赖

    pnpm i
    
  3. 打包

    pnpm run build
    
  4. 启动模拟 CDN 服务器,用于给物料使用

    node cdnMockupServer.js
    
  5. 展示组件库的 demo

    pnpm run dev
    

物料

materials/components/DemoCounter.json

{
  "component": "Counter",
  "name": {
    "zh_CN": "测试"
  },
  "icon": "button",
  "group": "Demo",
  "category": "Demo 组件库",
  "description": "",
  "tags": "",
  "keywords": "",
  "doc_url": "",
  "devMode": "proCode",
  "npm": {
    "package": "demo-lib",
    "exportName": "Counter",
    "destructuring": true
  },
  "configure": {
    "loop": true,
    "condition": true,
    "styles": true,
    "isContainer": false,
    "isModal": false,
    "isPopper": false,
    "isNullNode": false,
    "isLayout": false,
    "nestingRule": {
      "childWhitelist": "",
      "parentWhitelist": "",
      "descendantBlacklist": "",
      "ancestorWhitelist": ""
    },
    "rootSelector": "",
    "shortcuts": {
      "properties": [
        "count"
      ]
    },
    "contextMenu": {
      "actions": [
        "copy",
        "remove",
        "insert",
        "updateAttr",
        "bindEevent"
      ],
      "disable": []
    },
    "clickCapture": true,
    "framework": "Vue"
  },
  "schema": {
    "properties": [
      {
        "name": "0",
        "label": {
          "zh_CN": "基础属性"
        },
        "description": {
          "zh_CN": "组件的核心功能相关属性"
        },
        "content": [
          {
            "property": "count",
            "label": {
              "text": {
                "zh_CN": "计数"
              }
            },
            "description": "当前计数值",
            "required": false,
            "readOnly": false,
            "disabled": false,
            "cols": 12,
            "labelPosition": "left",
            "type": "number",
            "defaultValue": 0,
            "widget": {
              "component": "NumberConfigurator",
              "props": {
                "step": 1
              }
            }
          }
        ]
      }
    ],
    "events": {
      "onClickButton": {
        "name": "onClickButton",
        "description": "点击按钮时触发",
        "functionInfo": {
          "params": []
        }
      }
    },
    "slots": {}
  },
  "snippets": [
    {
      "name": {
        "zh_CN": "Counter"
      },
      "icon": "button",
      "snippetName": "Counter",
      "schema": {
        "props": {
          "count": 10
        }
      }
    }
  ]
}

materials/components/DemoHelloWorld.json

{
  "component": "HelloWorld",
  "name": {
    "zh_CN": "Hello World"
  },
  "icon": "HelloWorld",
  "group": "Demo",
  "category": "Demo 组件库",
  "description": "",
  "tags": "",
  "keywords": "",
  "doc_url": "",
  "devMode": "proCode",
  "npm": {
    "package": "demo-lib",
    "exportName": "HelloWorld",
    "destructuring": true
  },
  "configure": {
    "loop": true,
    "condition": true,
    "styles": true,
    "isContainer": false,
    "isModal": false,
    "isPopper": false,
    "isNullNode": false,
    "isLayout": false,
    "nestingRule": {
      "childWhitelist": "",
      "parentWhitelist": "",
      "descendantBlacklist": "",
      "ancestorWhitelist": ""
    },
    "rootSelector": "",
    "shortcuts": {
      "properties": [
        "msg"
      ]
    },
    "contextMenu": {
      "actions": [
        "copy",
        "remove",
        "insert",
        "updateAttr",
        "bindEevent"
      ],
      "disable": []
    },
    "framework": "Vue"
  },
  "schema": {
    "properties": [
      {
        "name": "0",
        "label": {
          "zh_CN": "基础属性"
        },
        "description": {
          "zh_CN": "组件的核心功能相关属性"
        },
        "content": [
          {
            "property": "msg",
            "label": {
              "text": {
                "zh_CN": "消息"
              }
            },
            "description": "显示在组件中的消息文本",
            "required": true,
            "readOnly": false,
            "disabled": false,
            "cols": 12,
            "labelPosition": "left",
            "type": "string",
            "defaultValue": "",
            "widget": {
              "component": "InputConfigurator",
              "props": {
                "placeholder": "请输入..."
              }
            }
          }
        ]
      }
    ],
    "events": {},
    "slots": {}
  },
  "snippets": [
    {
      "name": {
        "zh_CN": "Hello World"
      },
      "icon": "HelloWorld",
      "snippetName": "HelloWorld",
      "schema": {
        "props": {
          "msg": "World"
        }
      }
    }
  ]
}

materials/packages.json

{
  "packages": [
    {
      "name": "TinyVue组件库",
      "package": "@opentiny/vue",
      "version": "3.20.0",
      "destructuring": true,
      "script": "https://registry.npmmirror.com/@opentiny/vue-runtime/~3.20/files/dist3/tiny-vue-pc.mjs",
      "css": "https://registry.npmmirror.com/@opentiny/vue-theme/~3.20/files/index.css"
    },
    {
      "name": "element-plus组件库",
      "package": "element-plus",
      "version": "2.10.2",
      "destructuring": true,
      "script": "https://registry.npmmirror.com/element-plus/2.10.2/files/dist/index.full.mjs",
      "css": "https://registry.npmmirror.com/element-plus/2.10.2/files/dist/index.css"
    },
    {
      "name": "demo-lib 组件库",
      "package": "demo-lib",
      "version": "0.0.1",
      "destructuring": true,
      "script": "http://localhost:3000/dist/demo-lib.es.js",
      "css": "http://localhost:3000/dist/style.css"
    }
  ]
}

操作

拖入Demo 组件库/Counter 组件

What is expected

自定义组件库可以被画布和 preview 正常渲染,与自定义组件库 play (pnpm run dev) 下的效果一样

Image

What is actually happening

组件未被正确渲染

Image

控制台有 Warning, el-inputel-button 加载失败
Image

What is your project name

None

Any additional comments (optional)

虽然我已经在 Package 中引入了 element plus,但是在渲染时只会使用组件配置的组件库,组件库没有将 element plus bundled 进包中。我应该如何处理这样的情况,才能组件库正确渲染到画布上

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions