Skip to content

Commit

Permalink
feat: automatically detect vue version
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Feb 27, 2021
1 parent 821c35f commit 3e490c3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default {

## Vue 2 Support

From `v0.7`, we support Vue 2 with [`vite-plugin-vue2`](https://github.com/underfin/vite-plugin-vue2)
It just works.

```ts
// vite.config.js
Expand All @@ -96,9 +96,7 @@ import ViteComponents from 'vite-plugin-components'
export default {
plugins: [
createVuePlugin(),
ViteComponents({
transformer: 'vue2', // <--
}),
ViteComponents(),
],
}
```
Expand Down
4 changes: 1 addition & 3 deletions examples/vue2/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import ViteComponents from 'vite-plugin-components'
const config: UserConfig = {
plugins: [
createVuePlugin(),
ViteComponents({
transformer: 'vue2',
}),
ViteComponents(),
],
}

Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ function VitePluginComponents(options: Options = {}): Plugin {
name: 'vite-plugin-components',
enforce: 'post',
configResolved(config) {
if (config.plugins.find(i => i.name === 'vite-plugin-vue2'))
options.transformer = options.transformer || 'vue2'

ctx = new Context(options, config)
transformers = [
ctx.options.transformer === 'vue2'
Expand Down

0 comments on commit 3e490c3

Please sign in to comment.