我正在运行一个基于 TypeScript 的 Vue 项目,并尝试使用@vue/web-component-wrapper将其构建为 Web 组件。
相关代码:
// main.ts
import JovoWebClientVue, { JovoWebClientVueConfig } from 'jovo-client-web-vue';
import Vue from 'vue';
import App from './App.vue';
import wrap from '@vue/web-component-wrapper';
Vue.config.productionTip = false;
Vue.use<JovoWebClientVueConfig>(JovoWebClientVue, { /* cut */ });
new Vue({
render: (h) => h(App),
}).$mount('#app');
const wrappedElement = wrap(Vue, App);
window.customElements.define('v-card', wrappedElement);
// App.vue
<template>
<div id="app" class="w-screen h-screen">
<chat-widget />
</div>
</template>
<script lang="ts">
import ChatWidget from '@/components/ChatWidget.vue';
import { Component, Vue } from 'vue-property-decorator';
@Component({
components: { ChatWidget },
})
export default class App extends Vue {}
</script>
<style>
@import 'assets/css/theme.pcss';
#app {
-webkit-tap-highlight-color: transparent;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
</style>
运行构建命令时:
vue build --target wc --name my-custom-element ./src/main.ts
我收到以下错误:
Module parse failed: Unexpected character '@' (11:0)
You may need an additional loader to handle the result of these loaders.
| import { Component, Vue } from 'vue-property-decorator';
|
> @Component({
| components: { ChatWidget },
| })
知道如何解决这个问题吗?感谢所有帮助-谢谢。