Skip to content

Commit f846d10

Browse files
committed
fix: preview support custom-import-map
1 parent 6448af0 commit f846d10

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

packages/design-core/src/preview/src/preview/importMap.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
*
1111
*/
1212

13-
import { useEnv } from '@opentiny/tiny-engine-meta-register'
13+
import { useEnv, getMergeMeta } from '@opentiny/tiny-engine-meta-register'
1414
import { importMapConfig as importMapJSON } from '@opentiny/tiny-engine-common/js/importMap'
1515

1616
const importMap = {}
1717

1818
const opentinyVueVersion = '~3.20'
1919

20-
function replacePlaceholder(v) {
20+
function replacePlaceholder(v, k) {
2121
const {
2222
VITE_CDN_TYPE,
2323
VITE_CDN_DOMAIN,
@@ -29,6 +29,14 @@ function replacePlaceholder(v) {
2929
const versionDelimiter = VITE_CDN_TYPE === 'npmmirror' && !isLocalBundle ? '/' : '@'
3030
const fileDelimiter = VITE_CDN_TYPE === 'npmmirror' && !isLocalBundle ? '/files' : ''
3131
const cdnDomain = isLocalBundle ? BASE_URL + VITE_LOCAL_IMPORT_PATH : VITE_CDN_DOMAIN
32+
const customImportMap = getMergeMeta('engine.config')?.importMap
33+
34+
if (customImportMap?.imports?.[k]) {
35+
return customImportMap.imports[k]
36+
.replace('${VITE_CDN_DOMAIN}', cdnDomain)
37+
.replace('${versionDelimiter}', versionDelimiter)
38+
.replace('${fileDelimiter}', fileDelimiter)
39+
}
3240

3341
return v
3442
.replace('${VITE_CDN_DOMAIN}', cdnDomain)
@@ -39,7 +47,7 @@ function replacePlaceholder(v) {
3947

4048
export const getImportMap = (scripts = {}) => {
4149
importMap.imports = {
42-
...Object.fromEntries(Object.entries(importMapJSON.imports).map(([k, v]) => [k, replacePlaceholder(v)])),
50+
...Object.fromEntries(Object.entries(importMapJSON.imports).map(([k, v]) => [k, replacePlaceholder(v, k)])),
4351
...scripts
4452
}
4553

0 commit comments

Comments
 (0)