cmpt-huitu-cli 1.0.2 → 1.0.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cmpt-huitu-cli",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "description": "慧图前端项目工程化 CLI 工具",
6
6
  "main": "index.js",
@@ -25,6 +25,7 @@
25
25
  "lodash-es": "^4.17.21",
26
26
  "nprogress": "^0.2.0",
27
27
  "pinia": "^3.0.3",
28
+ "vxe-table": "^4.16.20",
28
29
  "vue": "^3.5.18",
29
30
  "vue-router": "^4.5.1"
30
31
  },
@@ -96,6 +96,8 @@ export default defineConfig(({ mode, command }) => {
96
96
  },
97
97
  // import引用可以忽略文件后缀如:import router from './router' === import router from './router/index.js'
98
98
  extensions: ['.mjs', '.ts', '.jsx', '.tsx', '.json', '.js', '.vue', '.css', '.scss'],
99
+ // 确保正确解析 CommonJS 模块,避免重复打包
100
+ dedupe: ['vxe-table', 'xe-utils'],
99
101
  },
100
102
 
101
103
  // CSS预处理器配置
@@ -120,6 +122,13 @@ export default defineConfig(({ mode, command }) => {
120
122
  sourcemap: !isProduction, // 开发保留 sourcemap
121
123
  target: ['es2015', 'edge88', 'chrome87'], // 产物目标浏览器
122
124
  minify: 'esbuild', // 代码压缩,vite默认使用esbuild,如果需要使用terser,需要安装npm install terser@vitejs/plugin-terser -D
125
+ // CommonJS 选项配置
126
+ commonjsOptions: {
127
+ // 将 CommonJS 模块转换为 ES 模块
128
+ transformMixedEsModules: true,
129
+ // 包含的 CommonJS 模块
130
+ include: [/xe-utils/, /vxe-table/],
131
+ },
123
132
  // 下面要配合 minify: 'terser',才能生效
124
133
  // terserOptions: isProduction
125
134
  // ? {
@@ -146,6 +155,7 @@ export default defineConfig(({ mode, command }) => {
146
155
  manualChunks: {
147
156
  'x-vuelib': ['vue', 'vue-router', 'pinia', 'axios', 'dayjs', 'lodash-es'],
148
157
  'x-eleuilib': ['element-plus'],
158
+ 'x-vxetable': ['vxe-table', 'xe-utils'],
149
159
  },
150
160
  experimentalMinChunkSize: 2048, // 该选项用于为代码分割设置一个以字节为单位的最小 chunk 大小
151
161
  // inlineDynamicImports: true // 该选项用于内联动态引入,该选项只在单页面应用的时候起作用
@@ -179,9 +189,20 @@ export default defineConfig(({ mode, command }) => {
179
189
  'dayjs/plugin/weekOfYear',
180
190
  'dayjs/plugin/isSameOrBefore',
181
191
  'dayjs/plugin/isSameOrAfter',
192
+ 'vxe-table',
193
+ 'xe-utils',
182
194
  ], // 默认情况下,不在 node_modules 中的,链接的包不会被预构建
183
195
  exclude: ['cmpt-huitu-ui', 'cmpt-huitu-utils'], // 在预构建中强制排除的依赖项
184
196
  force: false, // 强制进行依赖预构建
197
+ esbuildOptions: {
198
+ // 处理 CommonJS 模块(如 xe-utils)
199
+ format: 'esm',
200
+ // 支持 CommonJS
201
+ supported: {
202
+ 'dynamic-import': true,
203
+ 'import-meta': true,
204
+ },
205
+ },
185
206
  },
186
207
 
187
208
  // 下面要配合 minify: 'esbuild',才能生效
@@ -0,0 +1,106 @@
1
+ # 修复 vxe-table 依赖问题
2
+
3
+ ## 问题描述
4
+
5
+ 执行 `pnpm dev` 后,终端报错:
6
+ ```
7
+ [vite] Internal server error: Failed to resolve import "vxe-table" from "node_modules/.pnpm/cmpt-huitu-ui@1.0.1/node_modules/cmpt-huitu-ui/index.js?v=8ce970af". Does the file exist?
8
+ ```
9
+
10
+ 控制台报错:
11
+ ```
12
+ GET http://localhost:3002/node_modules/.pnpm/cmpt-huitu-ui@1.0.1/node_modules/cmpt-huitu-ui/index.js?v=8ce970af net::ERR_ABORTED 500 (Internal Server Error)
13
+ ```
14
+
15
+ ## 问题原因
16
+
17
+ `cmpt-huitu-ui` 包依赖 `vxe-table`,但项目的 `package.json` 中没有直接声明 `vxe-table` 依赖。在使用 pnpm 时,依赖提升机制可能没有正确提升 `vxe-table` 到项目的 `node_modules` 中,导致 Vite 无法解析该模块。
18
+
19
+ ## 解决方案
20
+
21
+ ### 方案 1:手动添加依赖(推荐)
22
+
23
+ 在项目根目录执行:
24
+
25
+ ```bash
26
+ pnpm add vxe-table@^4.16.20
27
+ ```
28
+
29
+ 或者使用 npm:
30
+
31
+ ```bash
32
+ npm install vxe-table@^4.16.20
33
+ ```
34
+
35
+ ### 方案 2:修改 package.json
36
+
37
+ 在项目的 `package.json` 的 `dependencies` 中添加:
38
+
39
+ ```json
40
+ {
41
+ "dependencies": {
42
+ "vxe-table": "^4.16.20",
43
+ // ... 其他依赖
44
+ }
45
+ }
46
+ ```
47
+
48
+ 然后执行:
49
+
50
+ ```bash
51
+ pnpm install
52
+ ```
53
+
54
+ ### 方案 3:配置 pnpm 依赖提升(可选)
55
+
56
+ 如果希望 pnpm 自动提升 `vxe-table`,可以在项目根目录创建 `.npmrc` 文件:
57
+
58
+ ```
59
+ shamefully-hoist=true
60
+ ```
61
+
62
+ 然后重新安装依赖:
63
+
64
+ ```bash
65
+ rm -rf node_modules pnpm-lock.yaml
66
+ pnpm install
67
+ ```
68
+
69
+ **注意**:`shamefully-hoist=true` 会让 pnpm 的行为更像 npm,可能会增加 `node_modules` 的大小。
70
+
71
+ ## 验证
72
+
73
+ 修复后,检查以下内容:
74
+
75
+ 1. ✅ `package.json` 中包含 `vxe-table` 依赖
76
+ 2. ✅ `node_modules` 中存在 `vxe-table` 目录
77
+ 3. ✅ 终端没有 `vxe-table` 相关错误
78
+ 4. ✅ 页面正常加载
79
+ 5. ✅ `VexTable` 组件可以正常使用
80
+
81
+ ## 预防措施
82
+
83
+ **对于新创建的项目**:
84
+
85
+ 模板已经更新,新创建的项目会自动包含 `vxe-table` 依赖,不会再出现此问题。
86
+
87
+ **对于已创建的项目**:
88
+
89
+ 请按照上述方案手动添加 `vxe-table` 依赖。
90
+
91
+ ## 相关依赖
92
+
93
+ `vxe-table` 的依赖关系:
94
+ - `vxe-table` 依赖 `xe-utils`
95
+ - `cmpt-huitu-ui` 依赖 `vxe-table`
96
+
97
+ 因此,项目中需要同时安装:
98
+ - `vxe-table`(已通过模板添加)
99
+ - `xe-utils`(会自动作为 `vxe-table` 的依赖安装)
100
+
101
+ ## 注意事项
102
+
103
+ - 确保 `vxe-table` 版本与 `cmpt-huitu-ui` 包中声明的版本兼容(当前为 `^4.16.20`)
104
+ - 如果使用 Monorepo,确保依赖正确安装
105
+ - 清理缓存后重新启动开发服务器
106
+
@@ -0,0 +1,158 @@
1
+ # 修复 xe-utils 导入错误
2
+
3
+ ## 问题描述
4
+
5
+ 执行 `pnpm dev` 后,控制台报错:
6
+ ```
7
+ Uncaught SyntaxError: The requested module '/node_modules/.pnpm/xe-utils@3.8.3/node_modules/xe-utils/index.js?v=e03718de' does not provide an export named 'default' (at config.js?v=e03718de:1:8)
8
+ ```
9
+
10
+ ## 问题原因
11
+
12
+ `xe-utils` 是 `vxe-table` 的依赖,是一个 CommonJS 模块。在 Vite 的 ESM 环境下,需要正确预构建和转换。
13
+
14
+ ## 解决方案
15
+
16
+ ### 方案 1:清理缓存并重启(推荐先尝试)
17
+
18
+ ```bash
19
+ # 1. 停止开发服务器(Ctrl+C)
20
+
21
+ # 2. 删除 Vite 缓存
22
+ rm -rf node_modules/.vite
23
+
24
+ # 3. 如果使用 pnpm,清理 pnpm 缓存
25
+ rm -rf node_modules/.pnpm
26
+
27
+ # 4. 重新安装依赖(可选,如果上述步骤无效)
28
+ pnpm install
29
+
30
+ # 5. 重新启动开发服务器
31
+ pnpm dev
32
+ ```
33
+
34
+ ### 方案 2:检查 vite.config.js 配置
35
+
36
+ 确保 `vite.config.js` 中包含以下配置:
37
+
38
+ ```javascript
39
+ export default defineConfig({
40
+ // ... 其他配置
41
+
42
+ // 优化依赖预构建
43
+ optimizeDeps: {
44
+ include: [
45
+ // ... 其他依赖
46
+ 'vxe-table',
47
+ 'xe-utils',
48
+ ],
49
+ exclude: ['cmpt-huitu-ui', 'cmpt-huitu-utils'],
50
+ esbuildOptions: {
51
+ format: 'esm',
52
+ supported: {
53
+ 'dynamic-import': true,
54
+ 'import-meta': true,
55
+ },
56
+ },
57
+ },
58
+
59
+ // 路径解析配置
60
+ resolve: {
61
+ // ... 其他配置
62
+ dedupe: ['vxe-table', 'xe-utils'],
63
+ },
64
+
65
+ // 构建配置
66
+ build: {
67
+ // ... 其他配置
68
+ commonjsOptions: {
69
+ transformMixedEsModules: true,
70
+ include: [/xe-utils/, /vxe-table/],
71
+ },
72
+ },
73
+ })
74
+ ```
75
+
76
+ ### 方案 3:如果上述方案无效,尝试强制重新构建
77
+
78
+ 在 `vite.config.js` 中临时设置:
79
+
80
+ ```javascript
81
+ optimizeDeps: {
82
+ // ... 其他配置
83
+ force: true, // 强制重新构建依赖
84
+ }
85
+ ```
86
+
87
+ 然后重启开发服务器。构建完成后,可以改回 `force: false`。
88
+
89
+ ### 方案 4:检查 vxe-table 版本
90
+
91
+ 如果问题仍然存在,可能是 `vxe-table` 版本与 `xe-utils` 版本不兼容。
92
+
93
+ 检查 `cmpt-huitu-ui` 包中的 `vxe-table` 版本:
94
+
95
+ ```bash
96
+ cd node_modules/cmpt-huitu-ui
97
+ cat package.json | grep vxe-table
98
+ ```
99
+
100
+ 如果版本过旧,可能需要更新 `cmpt-huitu-ui` 包。
101
+
102
+ ### 方案 5:使用 Vite 插件(最后手段)
103
+
104
+ 如果以上方案都无效,可以创建一个 Vite 插件来处理:
105
+
106
+ ```javascript
107
+ // vite/plugins/fixXeUtils.js
108
+ export default function fixXeUtils() {
109
+ return {
110
+ name: 'fix-xe-utils',
111
+ enforce: 'pre',
112
+ resolveId(id) {
113
+ if (id === 'xe-utils') {
114
+ return id
115
+ }
116
+ },
117
+ load(id) {
118
+ if (id === 'xe-utils') {
119
+ // 返回一个包装的 ESM 模块
120
+ return `
121
+ import * as xeUtils from 'xe-utils'
122
+ export default xeUtils
123
+ export * from 'xe-utils'
124
+ `
125
+ }
126
+ },
127
+ }
128
+ }
129
+ ```
130
+
131
+ 然后在 `vite.config.js` 中使用:
132
+
133
+ ```javascript
134
+ import fixXeUtils from './vite/plugins/fixXeUtils'
135
+
136
+ export default defineConfig({
137
+ plugins: [
138
+ // ... 其他插件
139
+ fixXeUtils(),
140
+ ],
141
+ // ... 其他配置
142
+ })
143
+ ```
144
+
145
+ ## 验证
146
+
147
+ 修复后,检查以下内容:
148
+
149
+ 1. ✅ 控制台没有 `xe-utils` 相关错误
150
+ 2. ✅ 页面正常加载
151
+ 3. ✅ `VexTable` 组件可以正常使用
152
+
153
+ ## 注意事项
154
+
155
+ - 如果使用 Monorepo,确保 `cmpt-huitu-ui` 包已正确发布并安装
156
+ - 清理缓存后,首次启动可能会较慢(需要重新预构建依赖)
157
+ - 如果问题持续存在,可能需要检查 `vxe-table` 和 `xe-utils` 的版本兼容性
158
+
Binary file
Binary file
Binary file