@hejiayue/x-markdown-test 0.0.1-beta.139 → 0.0.1-beta.140

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/vite-plugin.js +18 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hejiayue/x-markdown-test",
3
- "version": "0.0.1-beta.139",
3
+ "version": "0.0.1-beta.140",
4
4
  "description": "A markdown component library for Vue",
5
5
  "type": "module",
6
6
  "main": "./dist/x-markdown.cjs.js",
@@ -23,9 +23,22 @@ export function createXMarkdownVitePlugin(options = {}) {
23
23
  virtualModulesDir = './node_modules/@hejiayue/x-markdown-test/virtual-modules',
24
24
  } = options
25
25
 
26
+ // 存储虚拟模块的路径映射
27
+ const virtualModuleMap = new Map()
28
+
26
29
  return {
27
30
  name: '@hejiayue/x-markdown-test:vite-plugin',
28
31
  enforce: 'pre', // 在其他插件之前执行
32
+
33
+ // 拦截模块解析,包括动态导入
34
+ resolveId(id, importer) {
35
+ // 检查是否是我们需要处理的可选依赖
36
+ if (virtualModuleMap.has(id)) {
37
+ return virtualModuleMap.get(id)
38
+ }
39
+ return null
40
+ },
41
+
29
42
  config(config) {
30
43
  // 获取项目根目录
31
44
  const projectRoot = process.cwd()
@@ -55,15 +68,19 @@ export function createXMarkdownVitePlugin(options = {}) {
55
68
  }
56
69
 
57
70
  if (virtualModulePath) {
71
+ // 同时添加到 alias 和 resolveId 映射
58
72
  optionalAliases.push({
59
73
  find: dep,
60
74
  replacement: virtualModulePath,
61
75
  })
62
76
 
77
+ // 添加到 resolveId 映射表(用于动态导入)
78
+ virtualModuleMap.set(dep, virtualModulePath)
79
+
63
80
  // 在开发环境显示提示信息
64
81
  if (config.mode === 'development') {
65
82
  console.log(
66
- `\x1b[33m[@hejiayue/x-markdown-test]\x1b[0m ${dep} 未安装,使用虚拟模块`
83
+ `\x1b[33m[@hejiayue/x-markdown-test]\x1b[0m ${dep} 未安装,使用虚拟模块: ${virtualModulePath}`
67
84
  )
68
85
  }
69
86
  }