Skip to content

Commit

Permalink
fix: hmr error, peerDependencies error
Browse files Browse the repository at this point in the history
  • Loading branch information
Jevon617 committed Jun 28, 2023
1 parent 828cc62 commit 5a37bf4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"test:e2e": "pnpm -C playground test"
},
"peerDependencies": {
"@vue/compiler-sfc": ">=2.7.0 <=3.2.47"
"@vue/compiler-sfc": ">=2.7.0"
},
"dependencies": {
"cors": "^2.8.5",
Expand All @@ -99,20 +99,20 @@
"unplugin": "^0.10.2"
},
"devDependencies": {
"@antfu/eslint-config": "^0.38.5",
"@antfu/eslint-config": "^0.39.5",
"@types/cors": "^2.8.13",
"@types/debug": "^4.1.7",
"@types/debug": "^4.1.8",
"@types/etag": "^1.8.1",
"@types/node": "^18.16.4",
"@types/node": "^18.16.18",
"@types/svgo": "^2.6.4",
"@vue/compiler-sfc": "^3.2.47",
"@vue/compiler-sfc": "^3.3.4",
"bumpp": "^8.2.1",
"debug": "^4.3.4",
"eslint": "^8.39.0",
"eslint": "^8.43.0",
"esno": "^0.16.3",
"tsup": "^6.7.0",
"typescript": "^4.9.5",
"vitest": "^0.31.0",
"vue": "^3.2.47"
"vitest": "^0.32.2",
"vue": "^3.3.4"
}
}
18 changes: 10 additions & 8 deletions src/core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import createSvgSprite from './sprite'
import { LOAD_EVENT, UPDATE_EVENT, XMLNS, XMLNS_LINK } from './constants'

export async function genCode(options: Options, usedSvgNames: string[] | string, hmr: boolean) {
const isVueProject = detectProjectType(options)
const componentCode = await genComponent(options, isVueProject)
const isVue = isVueProject(options)
const componentCode = await genComponent(options)
const { svgSpriteDomId } = options

const { symbolIds, symbols, symbolCache } = await createSvgSprite(options, usedSvgNames)
Expand All @@ -21,7 +21,7 @@ export async function genCode(options: Options, usedSvgNames: string[] | string,

// only generate dts in serve
if (options?.dts && !Array.isArray(usedSvgNames))
genDts(symbolIds, options, isVueProject)
genDts(symbolIds, options)

const hmrCode = `
if (import.meta.hot) {
Expand Down Expand Up @@ -69,8 +69,9 @@ export const svgNames = ["${[...symbolIds].join('","')}"]
}
}

export function genDts(symbolIds: Set<string>, options: Options, isVueProject: boolean) {
if (isVueProject) {
export function genDts(symbolIds: Set<string>, options: Options) {
const isVue = isVueProject(options)
if (isVue) {
fs.writeFile(
path.resolve(options.dtsDir!, './svg-component.d.ts'),
replace(dts, symbolIds, options.componentName!),
Expand All @@ -88,9 +89,10 @@ export function genDts(symbolIds: Set<string>, options: Options, isVueProject: b
}
}

async function genComponent(options: Options, isVueProject: boolean) {
async function genComponent(options: Options) {
const isVue = isVueProject(options)
const { componentStyle, componentName, vueVersion } = options
if (!isVueProject) {
if (!isVue) {
return reactTemplate.replace(/\$component_name/, componentName!)
.replace(/\$component_style/, JSON.stringify(transformStyleStrToObject(componentStyle!)))
}
Expand Down Expand Up @@ -153,7 +155,7 @@ async function getVueVersion(vueVerison: VueVersion): Promise<'vue2' | 'vue3' |
}
}

function detectProjectType(options: Options) {
function isVueProject(options: Options) {
if (options.projectType === 'auto') {
try {
if (isPackageExists('vue'))
Expand Down

0 comments on commit 5a37bf4

Please sign in to comment.