fix: 优化 Playground 第三方资源入口

This commit is contained in:
sunlei 2026-05-16 11:08:46 +08:00
parent e339cba62b
commit f538ad924b
3 changed files with 27 additions and 11 deletions

View File

@ -13,21 +13,36 @@ export function isVaporSupported(version: string): boolean{
const esmBundle = (pkgName: string, externalVue = false) =>
`https://esm.sh/${pkgName}?bundle${externalVue ? '&external=vue' : ''}`
const ANT_DESIGN_VUE_VERSION = '4.2.6'
const ANT_DESIGN_ICONS_VERSION = '7.0.1'
const ELEMENT_PLUS_VERSION = '2.14.0'
const ELEMENT_PLUS_ICONS_VERSION = '2.3.2'
const LODASH_VERSION = '4.17.21'
// The preview iframe imports these packages on every run. Prefer bundled CDN
// entries to avoid hundreds of tiny ESM/icon requests exhausting the browser.
export const builtinLibraryImports: Record<string, string> = {
echarts: esmBundle('echarts@latest'),
'echarts/': 'https://esm.sh/echarts@latest/',
'ant-design-vue':
'https://cdn.jsdelivr.net/npm/ant-design-vue@4.2.6/dist/antd.esm.min.js',
'ant-design-vue/': 'https://esm.sh/ant-design-vue@4.2.6/',
'@ant-design/icons-vue': esmBundle('@ant-design/icons-vue@7.0.1', true),
'@ant-design/icons-vue/': 'https://esm.sh/@ant-design/icons-vue@7.0.1/',
'element-plus': esmBundle('element-plus@latest', true),
'element-plus/': 'https://esm.sh/element-plus@latest/',
'@element-plus/icons-vue': esmBundle('@element-plus/icons-vue@latest', true),
`https://cdn.jsdelivr.net/npm/ant-design-vue@${ANT_DESIGN_VUE_VERSION}/dist/antd.esm.min.js`,
'ant-design-vue/': `https://esm.sh/ant-design-vue@${ANT_DESIGN_VUE_VERSION}/`,
'@ant-design/icons-vue': esmBundle(
`@ant-design/icons-vue@${ANT_DESIGN_ICONS_VERSION}`,
true,
),
'@ant-design/icons-vue/': `https://esm.sh/@ant-design/icons-vue@${ANT_DESIGN_ICONS_VERSION}/`,
'element-plus': `https://cdn.jsdelivr.net/npm/element-plus@${ELEMENT_PLUS_VERSION}/dist/index.full.min.mjs`,
'element-plus/': `https://cdn.jsdelivr.net/npm/element-plus@${ELEMENT_PLUS_VERSION}/`,
'@element-plus/icons-vue': esmBundle(
`@element-plus/icons-vue@${ELEMENT_PLUS_ICONS_VERSION}`,
true,
),
'@element-plus/icons-vue/':
'https://esm.sh/@element-plus/icons-vue@latest/',
`https://esm.sh/@element-plus/icons-vue@${ELEMENT_PLUS_ICONS_VERSION}/`,
'lodash-es': esmBundle(`lodash-es@${LODASH_VERSION}`),
'lodash-es/': `https://cdn.jsdelivr.net/npm/lodash-es@${LODASH_VERSION}/`,
lodash: esmBundle(`lodash@${LODASH_VERSION}`),
}
export function useVueImportMap(

View File

@ -64,7 +64,7 @@ let stopUpdateWatcher: WatchStopHandle | undefined
const builtinLibraryHeadHTML = `
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ant-design-vue@4.2.6/dist/reset.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/element-plus@latest/dist/index.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/element-plus@2.14.0/dist/index.css">
`
const antDesignVueModule = 'ant-design' + '-vue'

View File

@ -29,8 +29,9 @@ export const builtinDependencyVersions: Record<string, string> = {
echarts: 'latest',
'ant-design-vue': 'latest',
'@ant-design/icons-vue': 'latest',
'element-plus': 'latest',
'@element-plus/icons-vue': 'latest',
'element-plus': '2.14.0',
'@element-plus/icons-vue': '2.3.2',
'lodash-es': '4.17.21',
}
export function useStore(