Skip to content

Commit 73fad9e

Browse files
committed
docs: update example and usage with mkdist
1 parent bb98176 commit 73fad9e

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

README.md

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pnpm install vue-sfc-transformer
2020
```
2121

2222
```js
23-
import { parse as parseDOM } from '@vue/compiler-dom'
2423
import { parse as parseSFC } from '@vue/compiler-sfc'
2524
import { transform } from 'esbuild'
2625

@@ -38,40 +37,28 @@ defineProps<{
3837
</script>
3938
`
4039

41-
const transpiledTemplate = await transpileVueTemplate(
42-
src,
43-
parseDOM(src, { parseMode: 'base' }),
44-
0,
40+
const sfc = parseSFC(src, {
41+
filename: 'test.vue',
42+
ignoreEmpty: true,
43+
})
44+
45+
// transpile template block
46+
const templateBlockContents = await transpileVueTemplate(
47+
sfc.descriptor.template.content,
48+
sfc.descriptor.template.ast,
49+
sfc.descriptor.template.loc.start.offset,
4550
async (code) => {
4651
const res = await transform(code, { loader: 'ts', target: 'esnext' })
4752
return res.code
4853
},
4954
)
50-
51-
console.log(transpiledTemplate)
52-
// <template>
53-
// <div v-if="test" />
54-
// </template>
55-
//
56-
// <script setup lang="ts">
57-
// defineProps<{
58-
// test?: string
59-
// }>()
60-
// </script>
61-
62-
const sfc = parseSFC(transpiledTemplate, {
63-
filename: 'test.vue',
64-
ignoreEmpty: true,
65-
})
55+
console.log(templateBlockContents)
56+
// <div v-if="test" />
6657

6758
const { content: scriptBlockContents } = await preTranspileScriptSetup(sfc.descriptor, 'test.vue')
6859
console.log(scriptBlockContents)
69-
7060
// defineProps({
71-
// test: {
72-
// type: String,
73-
// required: false
74-
// }
61+
// test: { type: String, required: false }
7562
// })
7663
```
7764

@@ -81,6 +68,8 @@ If you are using `mkdist`, `vue-sfc-transformer` exports a loader you can use:
8168
import { vueLoader } from 'vue-sfc-transformer/mkdist'
8269
```
8370

71+
> `mkdist` will automatically use the loader from `vue-sfc-transformer` when you pass `vue` to the `loaders` option and have this package installed.
72+
8473
## 💻 Development
8574

8675
- Clone this repository

0 commit comments

Comments
 (0)