Skip to content

Commit

Permalink
docs(plugin-vue): add custom block transform example
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 1, 2021
1 parent dd80760 commit c98a157
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/plugin-vue/README.md
Expand Up @@ -11,6 +11,32 @@ export default {
}
```

## Example for transforming custom blocks

```ts
// vite.config.js
import vue from '@vitejs/plugin-vue'

const vueI18nPlugin = {
name: 'vue-i18n',
transform(code, id) {
if (!/vue&type=i18n/.test(id)) {
return
}
if (/\.ya?ml$/.test(id)) {
code = JSON.stringify(require('js-yaml').safeLoad(code.trim()))
}
return `export default Comp => {
Comp.i18n = ${code}
}`
}
}

export default {
plugins: [vue(), vueI18nPlugin]
}
```

## License

MIT

0 comments on commit c98a157

Please sign in to comment.