Skip to content

Commit

Permalink
fix: change vue default version from '2' to 'undefined', because othe…
Browse files Browse the repository at this point in the history
…r project type like react did not need dependencies relate to vue
  • Loading branch information
Chieffo2021 committed Jul 23, 2021
1 parent 21e77a1 commit 1df395f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/constants/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const DEFAULT_VUE_VERSION = 2
export const DEFAULT_VUE_VERSION = undefined
export const VUE_COMPILER_SFC_VERSION = '^3.0.5'
export const VITE_VERSION = '2.3.8'
export const VITE_PLUGIN_VUE_VERSION = '^1.2.1'
Expand Down
2 changes: 1 addition & 1 deletion src/transform/context.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ViteConfig } from '../config/vite'

export interface TransformContext {
vueVersion : number;
vueVersion : number | undefined;
config : ViteConfig;
importers : string[];
}
2 changes: 1 addition & 1 deletion src/transform/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function transformImporters (context: TransformContext) : void {
plugins.push(new RawValue('vue()'))
context.importers.push('import vueJsx from \'@vitejs/plugin-vue-jsx\';')
plugins.push(new RawValue('vueJsx()'))
} else {
} else if (context.vueVersion === 2) {
context.importers.push(
'import { createVuePlugin } from \'vite-plugin-vue2\';'
)
Expand Down
7 changes: 4 additions & 3 deletions src/utils/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path'
import { readSync } from './file'
import { DEFAULT_VUE_VERSION } from '../constants/constants'
import fs from 'fs'
import { minVersion } from 'semver'

export function getVueVersion (rootDir: string): number {
const vueVersion = DEFAULT_VUE_VERSION
Expand All @@ -22,12 +23,12 @@ export function getVueVersion (rootDir: string): number {
}
source = readSync(nodePath)
jsonObj = JSON.parse(source)
if (jsonObj === '' || dep.vue === undefined) {
if (jsonObj === '') {
return vueVersion
}
return Number(jsonObj.version.replace(/~|\^/, '').split('.')[0])
return Number(minVersion(jsonObj.version).split('.')[0])
}
return Number(dep.vue.replace(/~|\^/, '').split('.')[0])
return Number(minVersion(dep.vue).split('.')[0])
}

function getVueDependency (jsonObj: any) : any {
Expand Down

0 comments on commit 1df395f

Please sign in to comment.