使用vite库模式打包的组件,在html esm 下无法使用
Vue version
3.2.45
Link to minimal reproduction
https://github.com/ddmy/vite-build-qs
Steps to reproduce
错误复现路径:
- vite.config.js 配置 库模式,导出HelloWorld.vue组件
- 在index.html中采用script type="module"的方式使用该组件,没有正确的响应
https://cdn.bootcdn.net/ajax/libs/vue/3.2.45/vue.esm-browser.js (提示组件引入方式不对)和 https://cdn.bootcdn.net/ajax/libs/vue/3.2.45/vue.esm-browser.prod.js (没有报错信息)都不行
What is expected?
组件可正常展示,且传入props能正常展示
What is actually happening?
组件不可用
System Info
No response
Any additional comments?
No response
<script type="module">
- import { createApp } from "https://cdn.bootcdn.net/ajax/libs/vue/3.2.45/vue.esm-browser.js"
+ import { createApp } from "vue"
import HelloWorld from './HelloWorld.es.js'
console.log('HelloWorld', HelloWorld)
const app = createApp({
components: {
HelloWorld
},
setup () {
return {}
}
}).mount('#app')
</script>
<script type="module"> - import { createApp } from "https://cdn.bootcdn.net/ajax/libs/vue/3.2.45/vue.esm-browser.js" + import { createApp } from "vue" import HelloWorld from './HelloWorld.es.js' console.log('HelloWorld', HelloWorld) const app = createApp({ components: { HelloWorld }, setup () { return {} } }).mount('#app') </script>
你好,我想知道你是如何运行html目录下的index.html的?我这边通过http-server
启动后,页面所使用的HelloWorld
组件并不能正常加载,而是直接加载出了<helloworld msg="Vite + Vue" msg2="hhhhhh" msg3="5555"></helloworld>