Skip to content

Commit c98a157

Browse files
committed
docs(plugin-vue): add custom block transform example
1 parent dd80760 commit c98a157

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Diff for: packages/plugin-vue/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,32 @@ export default {
1111
}
1212
```
1313

14+
## Example for transforming custom blocks
15+
16+
```ts
17+
// vite.config.js
18+
import vue from '@vitejs/plugin-vue'
19+
20+
const vueI18nPlugin = {
21+
name: 'vue-i18n',
22+
transform(code, id) {
23+
if (!/vue&type=i18n/.test(id)) {
24+
return
25+
}
26+
if (/\.ya?ml$/.test(id)) {
27+
code = JSON.stringify(require('js-yaml').safeLoad(code.trim()))
28+
}
29+
return `export default Comp => {
30+
Comp.i18n = ${code}
31+
}`
32+
}
33+
}
34+
35+
export default {
36+
plugins: [vue(), vueI18nPlugin]
37+
}
38+
```
39+
1440
## License
1541

1642
MIT

0 commit comments

Comments
 (0)