Closed marxangels closed 2 years ago
please provide a minimalist testcase
foo.vue
<template>
<div></div>
</template>
<script>
import foo from '/lib/bar.js'
export default { }
</script>
@FranckFreiburger it seems the error is caused by the import
statement, whatever the script content is.
please give your entry point file (the file where you call loadModule()
load-vue.js
import '/vue/vue3-sfc-loader.js'
const {loadModule} = window['vue3-sfc-loader']
const options = {
moduleCache: {vue: Vue},
async getFile(url) {
let res = await fetch(url)
if (!res.ok) throw new Error(res.statusText + ' ' + url)
let content = await res.text()
return url.endsWith(".js") ? {content, extname: ".mjs"} : content
},
addStyle(textContent) {
const style = Object.assign(document.createElement('style'), {textContent})
const ref = document.head.getElementsByTagName('style')[0] || null
document.head.insertBefore(style, ref)
},
}
export default function (url) {
return Vue.defineAsyncComponent(() => loadModule(url, options))
}
@FranckFreiburger is there something wrong?
yes, your getFile()
is not up to date.
see https://github.com/FranckFreiburger/vue3-sfc-loader/blob/main/CHANGELOG.md#-breaking-changes and https://github.com/FranckFreiburger/vue3-sfc-loader#example
Great! It works fine. Thank you, Franck.
version
0.8.4