create-vite-vue 1.4.0 → 1.5.0
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/bin/index.js
CHANGED
|
@@ -1,10 +1,36 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
import { execSync } from 'child_process'
|
|
3
3
|
import fs from 'fs'
|
|
4
4
|
import path from 'path'
|
|
5
5
|
import prompts from 'prompts'
|
|
6
6
|
import { fileURLToPath } from 'url'
|
|
7
7
|
|
|
8
|
+
// 检测 Node 版本
|
|
9
|
+
const requiredVersion = '22.19.0'
|
|
10
|
+
|
|
11
|
+
function compareVersion (v1, v2) {
|
|
12
|
+
const a = v1.split('.').map(Number)
|
|
13
|
+
const b = v2.split('.').map(Number)
|
|
14
|
+
|
|
15
|
+
for(let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
16
|
+
const n1 = a[i] || 0
|
|
17
|
+
const n2 = b[i] || 0
|
|
18
|
+
if(n1 > n2) return 1
|
|
19
|
+
if(n1 < n2) return -1
|
|
20
|
+
}
|
|
21
|
+
return 0
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const currentVersion = process.version.replace('v', '')
|
|
25
|
+
|
|
26
|
+
if(compareVersion(currentVersion, requiredVersion) < 0) {
|
|
27
|
+
console.error(`❌ Node.js 版本过低`)
|
|
28
|
+
console.error(`当前版本: ${currentVersion}`)
|
|
29
|
+
console.error(`最低要求: ${requiredVersion}`)
|
|
30
|
+
console.error(`请升级 Node.js 后再运行`)
|
|
31
|
+
process.exit(1)
|
|
32
|
+
}
|
|
33
|
+
|
|
8
34
|
const __filename = fileURLToPath(import.meta.url)
|
|
9
35
|
const __dirname = path.dirname(__filename)
|
|
10
36
|
|
|
@@ -42,37 +68,36 @@ const __dirname = path.dirname(__filename)
|
|
|
42
68
|
]
|
|
43
69
|
})
|
|
44
70
|
|
|
45
|
-
// 2️⃣
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
])
|
|
71
|
+
// 2️⃣ 功能选择(多选)
|
|
72
|
+
const { featureList } = await prompts({
|
|
73
|
+
type: 'multiselect',
|
|
74
|
+
name: 'featureList',
|
|
75
|
+
message: '请选择基础功能(↑↓选择,空格确认,回车完成)',
|
|
76
|
+
instructions: false,
|
|
77
|
+
choices: [
|
|
78
|
+
{ title: 'Vue Router', value: 'router' },
|
|
79
|
+
{ title: 'Pinia(含持久化)', value: 'pinia' },
|
|
80
|
+
{ title: 'Axios', value: 'axios' },
|
|
81
|
+
{ title: 'Element Plus(PC UI)', value: 'element' },
|
|
82
|
+
{ title: 'Vant(Mobile UI)', value: 'vant' },
|
|
83
|
+
{ title: 'VueUse(实用 Composition API)', value: 'vueuse' },
|
|
84
|
+
{ title: 'Lodash(工具库)', value: 'lodash' },
|
|
85
|
+
{ title: 'Day.js(日期处理)', value: 'dayjs' },
|
|
86
|
+
{ title: 'Tailwind CSS(原子化 CSS)', value: 'tailwind' }
|
|
87
|
+
]
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
// 转换成原来的结构(保证后面代码基本不用动)
|
|
91
|
+
const features = {
|
|
92
|
+
router: featureList?.includes('router') || false,
|
|
93
|
+
pinia: featureList?.includes('pinia') || false,
|
|
94
|
+
axios: featureList?.includes('axios') || false,
|
|
95
|
+
ui: featureList?.filter(v => ['element', 'vant'].includes(v)) || []
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const extraPlugins = featureList?.filter(v =>
|
|
99
|
+
['vueuse', 'lodash', 'dayjs', 'tailwind'].includes(v)
|
|
100
|
+
) || []
|
|
76
101
|
|
|
77
102
|
// 询问是否开启自动路由
|
|
78
103
|
let autoRoute = false
|
|
@@ -88,40 +113,6 @@ const __dirname = path.dirname(__filename)
|
|
|
88
113
|
autoRoute = enableAutoRoute
|
|
89
114
|
}
|
|
90
115
|
|
|
91
|
-
// ========== 新增:增强插件配置 ==========
|
|
92
|
-
let extraPlugins = []
|
|
93
|
-
|
|
94
|
-
const { wantExtra } = await prompts({
|
|
95
|
-
type: 'toggle',
|
|
96
|
-
name: 'wantExtra',
|
|
97
|
-
message: '是否需要添加额外工具?',
|
|
98
|
-
initial: false,
|
|
99
|
-
active: '是',
|
|
100
|
-
inactive: '否'
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
if(wantExtra) {
|
|
104
|
-
const pluginOptions = [
|
|
105
|
-
{ title: 'VueUse(实用 Composition API)', value: 'vueuse' },
|
|
106
|
-
{ title: 'Lodash(实用工具库)', value: 'lodash' },
|
|
107
|
-
{ title: 'Day.js(轻量日期处理)', value: 'dayjs' },
|
|
108
|
-
{ title: 'Tailwind CSS(原子化 CSS)', value: 'tailwind' }
|
|
109
|
-
]
|
|
110
|
-
|
|
111
|
-
const { selectedPlugins } = await prompts({
|
|
112
|
-
type: 'multiselect',
|
|
113
|
-
name: 'selectedPlugins',
|
|
114
|
-
message: '请选择额外工具(↑↓选择,空格确认,回车完成)',
|
|
115
|
-
choices: pluginOptions.map(p => ({ title: p.title, value: p.value })),
|
|
116
|
-
instructions: false
|
|
117
|
-
})
|
|
118
|
-
|
|
119
|
-
if(selectedPlugins?.length) {
|
|
120
|
-
extraPlugins = selectedPlugins
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
// ========== 增强插件配置结束 ==========
|
|
124
|
-
|
|
125
116
|
// 3️⃣ 是否立即运行 dev
|
|
126
117
|
const { runDev } = await prompts({
|
|
127
118
|
type: 'select',
|
|
@@ -184,13 +175,13 @@ const __dirname = path.dirname(__filename)
|
|
|
184
175
|
'/* __PINIA_IMPORT__ */': features.pinia
|
|
185
176
|
? "import { createPinia } from 'pinia'\nimport persistedstate from 'pinia-plugin-persistedstate'"
|
|
186
177
|
: '',
|
|
187
|
-
'/* __ELEMENT_IMPORT__ */': features.ui
|
|
178
|
+
'/* __ELEMENT_IMPORT__ */': features.ui.includes('element')
|
|
188
179
|
? `import ElementPlus from 'element-plus'
|
|
189
180
|
import zhCn from 'element-plus/es/locale/lang/zh-cn'
|
|
190
181
|
import 'element-plus/dist/index.css'
|
|
191
182
|
import * as ElementPlusIconsVue from '@element-plus/icons-vue'`
|
|
192
183
|
: '',
|
|
193
|
-
'/* __VANT_IMPORT__ */': features.ui
|
|
184
|
+
'/* __VANT_IMPORT__ */': features.ui.includes('vant')
|
|
194
185
|
? `import Vant from 'vant'
|
|
195
186
|
import 'vant/lib/index.css'`
|
|
196
187
|
: '',
|
|
@@ -198,13 +189,13 @@ import 'vant/lib/index.css'`
|
|
|
198
189
|
'/* __PINIA_USE__ */': features.pinia
|
|
199
190
|
? 'app.use(createPinia().use(persistedstate))'
|
|
200
191
|
: '',
|
|
201
|
-
'/* __ELEMENT_USE__ */': features.ui
|
|
192
|
+
'/* __ELEMENT_USE__ */': features.ui.includes('element')
|
|
202
193
|
? `app.use(ElementPlus, { locale: zhCn })
|
|
203
194
|
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
|
204
195
|
app.component(key, component)
|
|
205
196
|
}`
|
|
206
197
|
: '',
|
|
207
|
-
'/* __VANT_USE__ */': features.ui
|
|
198
|
+
'/* __VANT_USE__ */': features.ui.includes('vant')
|
|
208
199
|
? 'app.use(Vant)'
|
|
209
200
|
: ''
|
|
210
201
|
}
|
|
@@ -234,21 +225,21 @@ for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
|
|
234
225
|
let pkg = fs.readFileSync(pkgTpl, 'utf-8')
|
|
235
226
|
|
|
236
227
|
const optionalDeps = {}
|
|
237
|
-
if(features.router) optionalDeps['vue-router'] = '^
|
|
228
|
+
if(features.router) optionalDeps['vue-router'] = '^5.0.3'
|
|
238
229
|
if(features.pinia) {
|
|
239
|
-
optionalDeps['pinia'] = '^
|
|
240
|
-
optionalDeps['pinia-plugin-persistedstate'] = '^
|
|
230
|
+
optionalDeps['pinia'] = '^3.0.4'
|
|
231
|
+
optionalDeps['pinia-plugin-persistedstate'] = '^4.7.1'
|
|
241
232
|
}
|
|
242
|
-
if(features.axios) optionalDeps['axios'] = '^1.
|
|
243
|
-
if(features.ui
|
|
244
|
-
optionalDeps['element-plus'] = '^2.
|
|
245
|
-
optionalDeps['@element-plus/icons-vue'] = '^2.3.
|
|
233
|
+
if(features.axios) optionalDeps['axios'] = '^1.13.6'
|
|
234
|
+
if(features.ui.includes('element')) {
|
|
235
|
+
optionalDeps['element-plus'] = '^2.13.3'
|
|
236
|
+
optionalDeps['@element-plus/icons-vue'] = '^2.3.2'
|
|
246
237
|
}
|
|
247
|
-
if(features.ui
|
|
238
|
+
if(features.ui.includes('vant')) {
|
|
248
239
|
optionalDeps['vant'] = '^4.9.22'
|
|
249
240
|
}
|
|
250
241
|
// 增强插件依赖
|
|
251
|
-
if(extraPlugins.includes('vueuse')) optionalDeps['@vueuse/core'] = '^14.1
|
|
242
|
+
if(extraPlugins.includes('vueuse')) optionalDeps['@vueuse/core'] = '^14.2.1'
|
|
252
243
|
if(extraPlugins.includes('dayjs')) optionalDeps['dayjs'] = '^1.11.19'
|
|
253
244
|
if(extraPlugins.includes('lodash')) optionalDeps['lodash'] = '^4.17.23'
|
|
254
245
|
if(autoRoute) optionalDeps['vite-plugin-pages'] = '^0.33.3'
|
package/package.json
CHANGED
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"less": "^4.5.1",
|
|
13
13
|
"tslib": "^2.8.1",
|
|
14
|
-
"vue": "^3.5.
|
|
14
|
+
"vue": "^3.5.25"__OPTIONAL_DEP__
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@vitejs/plugin-vue": "^6.0.
|
|
18
|
-
"vite": "
|
|
17
|
+
"@vitejs/plugin-vue": "^6.0.2",
|
|
18
|
+
"vite": "^8.0.0-beta.13"
|
|
19
19
|
},
|
|
20
20
|
"overrides": {
|
|
21
|
-
"vite": "
|
|
21
|
+
"vite": "^8.0.0-beta.13"
|
|
22
22
|
}
|
|
23
23
|
}
|
|
@@ -11,17 +11,17 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"less": "^4.5.1",
|
|
13
13
|
"tslib": "^2.8.1",
|
|
14
|
-
"vue": "^3.5.
|
|
14
|
+
"vue": "^3.5.25"__OPTIONAL_DEP__
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@types/node": "^24.
|
|
18
|
-
"@vitejs/plugin-vue": "^6.0.
|
|
17
|
+
"@types/node": "^24.11.0",
|
|
18
|
+
"@vitejs/plugin-vue": "^6.0.2",
|
|
19
19
|
"@vue/tsconfig": "^0.8.1",
|
|
20
20
|
"typescript": "~5.9.3",
|
|
21
|
-
"vite": "
|
|
22
|
-
"vue-tsc": "^3.1.
|
|
21
|
+
"vite": "^8.0.0-beta.13",
|
|
22
|
+
"vue-tsc": "^3.1.5"
|
|
23
23
|
},
|
|
24
24
|
"overrides": {
|
|
25
|
-
"vite": "
|
|
25
|
+
"vite": "^8.0.0-beta.13"
|
|
26
26
|
}
|
|
27
27
|
}
|