Skip to content

Commit e73b3ea

Browse files
author
蒋志强
committed
fix: import vue version is not only
1 parent fcebb3e commit e73b3ea

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

src/config.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,20 @@ export enum npmCdnEnum {
99

1010
export const DEFAULT_CDN = npmCdnEnum.unpkg
1111

12+
/**
13+
* get cdn url by package name & filePath
14+
* if use unpkg cdn, url will add query params: ?module'
15+
*/
16+
export const getCdnUrl = (npmName: string, filePath?: string) => {
17+
if (DEFAULT_CDN === npmCdnEnum.unpkg) {
18+
return `${DEFAULT_CDN}/${npmName}?module`
19+
}
20+
21+
return `${DEFAULT_CDN}/${npmName}/${filePath}`
22+
}
23+
1224
/** get vue runtime cdn url buy version */
13-
export const getVueRuntimeURL = (version: string) => `${DEFAULT_CDN}/@vue/runtime-dom@${version}/dist/runtime-dom.esm-browser.js`
25+
export const getVueRuntimeURL = (version?: string) => getCdnUrl('vue' + (version ? `@${version}` : ''))
1426

1527
/** get vue compiler cdn url buy version */
1628
export const getVueCompilerURL = (version: string) => `${DEFAULT_CDN}/@vue/compiler-sfc@${version}/dist/compiler-sfc.esm-browser.js`
@@ -33,25 +45,17 @@ export const getVantURL = (version?: string) => {
3345
export const defaultMainFile = 'App.vue'
3446
export const vantInjectPlugin = 'vant-inject-plugin.js'
3547

36-
/**
37-
* get cdn url by package name & filePath
38-
* if use unpkg cdn, url will add query params: ?module'
39-
*/
40-
export const getCdnUrl = (npmName: string, filePath?: string) => {
41-
if (DEFAULT_CDN === npmCdnEnum.unpkg) {
42-
return `${DEFAULT_CDN}/${npmName}?module`
43-
}
44-
45-
return `${DEFAULT_CDN}/${npmName}/${filePath}`
46-
}
47-
4848
export const vantImports: Record<string, string> = {
4949
vant: getVantURL(),
5050
'@vant/use': getCdnUrl('@vant/use', '/dist/index.esm.mjs'),
5151
'@vant/popperjs': getCdnUrl('@vant/popperjs', '/dist/index.esm.mjs'),
5252
'@vant/touch-emulator': `${DEFAULT_CDN}/@vant/touch-emulator`
5353
}
5454

55+
export const vueImports: Record<string, string> = {
56+
vue: getVueRuntimeURL()
57+
}
58+
5559
export const additionalImports = {
5660
...vantImports
5761
}

src/helpers.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { vantImports } from './config'
1+
import { vantImports, vueImports } from './config'
22

33
/**
44
* fix wrong cdn url already in use
@@ -11,11 +11,18 @@ export const convertBugImportMapCdnUrl = (importMap: Record<string, string>) =>
1111
}, {
1212
name: '@vant/popperjs',
1313
filepath: '/dist/esm/index.js'
14+
}, {
15+
name: 'vue',
16+
filepath: '/dist/runtime-dom.esm-browser.js'
1417
}]
1518

1619
someBugImportData.forEach(({ name, filepath }) => {
17-
if (importMap[name]?.endsWith(filepath) && vantImports[name]) {
18-
importMap[name] = vantImports[name]
20+
if (importMap[name]?.endsWith(filepath)) {
21+
if (vantImports[name]) {
22+
importMap[name] = vantImports[name]
23+
} else if (vueImports[name]) {
24+
importMap[name] = vueImports[name]
25+
}
1926
}
2027
})
2128
}

0 commit comments

Comments
 (0)