vue.js - Vue 3 Web 组件不会构建,而是抛出错误

标签 vue.js web-component vuejs3

我使用 vue cli 创建了一个新的 vue 项目,然后调整了 main.js 以支持 Web 组件:

import Vue from 'vue';
import wrap from '@vue/web-component-wrapper';
import HelloWorld from "./components/HelloWorld";

const CustomElement = wrap(Vue, HelloWorld);

window.customElements.define('my-custom-element', CustomElement);

运行 vue-cli-service build --target wc 时出现以下错误:

ERROR  Vue 3 support of the web component target is still under development.

我无法弄清楚为什么会出现此错误以及我可以采取什么措施来修复它。



包.json:

...
"dependencies": {
   "@vue/web-component-wrapper": "^1.2.0",
   "core-js": "^3.6.5",
   "vue": "^3.0.2"
 },
 "devDependencies": {
   "@vue/cli-plugin-babel": "~4.5.0",
   "@vue/cli-plugin-eslint": "~4.5.0",
   "@vue/cli-service": "^4.5.4",
   "@vue/compiler-sfc": "^3.0.0",
   "babel-eslint": "^10.1.0",
   "eslint": "^6.7.2",
   "eslint-plugin-vue": "^7.0.0-0"
 },
...

我使用@vue/cli版本4.5.9。

最佳答案

您好,这里有更新。主题见 issue on github并评论twitter看起来 vue 3.2.0 我们又恢复了这个功能,我创建了一个小 stackblitz但如您所见,样式未应用

关于vue.js - Vue 3 Web 组件不会构建,而是抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64890650/

相关文章:

javascript - 每当路由更改时如何提交突变以存储

javascript - 当我们使用槽时如何使用javascript找到父元素宽度

reactjs - 我如何使用我的 React 组件作为 Web 组件,只需 javascript 标签调用

javascript - 我的 &lt;script&gt; 应该在我的 <dom-module> 内吗?

unit-testing - 如何在 vitest、vue/test-utils vue3 中对 vueuse/head 进行单元测试

typescript - Vue/Typescript/Jest - Jest 单元测试语法错误 : Unexpected token import

vue.js - vue-cli3公共(public)文件夹img不显示

javascript - 如何将事件处理程序分配给自定义元素

rollup - 使用汇总设置 vue3?

css - 为什么折叠动画在 vue3 中不起作用?