create-vite-vue 1.5.7 → 1.6.1

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/README.md CHANGED
@@ -21,6 +21,7 @@
21
21
  - 🎨 可选集成 Tailwind CSS(通过 postcss 配置)
22
22
  - 🟢 支持多种包管理器:npm / pnpm,可根据环境自动识别并使用
23
23
  - 🔔 可选集成 Mitt(轻量事件总线,实现组件间解耦通信)
24
+ - 🛡️ 可选集成 mkcert 插件,实现本地 HTTPS 开发环境
24
25
 
25
26
  ---
26
27
 
@@ -36,6 +37,7 @@
36
37
  🧰 VueUse · Lodash · Day.js
37
38
  🎨 Tailwind CSS
38
39
  🔔 Mitt
40
+ 🛡️ mkcert (本地 HTTPS)
39
41
 
40
42
  ---
41
43
 
@@ -230,6 +232,34 @@ console.log(route.params.id)
230
232
  console.log(route.params.name)
231
233
  ```
232
234
 
235
+ ### ✅ meta.json 自动注入路由
236
+
237
+ 在每个页面目录下可以新增一个 `meta.json` 文件:
238
+
239
+ ```text
240
+ src/views/home/
241
+ ├─ index.vue
242
+ └─ meta.json
243
+ ```
244
+
245
+ #### 示例:
246
+
247
+ ```json
248
+ {
249
+ "name": "首页",
250
+ "orderMenu": 1
251
+ }
252
+ ```
253
+
254
+ 👉 脚手架会自动读取该文件,并注入到对应路由的 `meta` 属性中:
255
+
256
+ ```js
257
+ route.meta = {
258
+ name: "首页",
259
+ orderMenu: 1
260
+ }
261
+ ```
262
+
233
263
  ---
234
264
 
235
265
  ### 4️⃣ 页面内容与样式
package/bin/index.js CHANGED
@@ -1,4 +1,4 @@
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'
@@ -101,7 +101,8 @@ const pkgCommands = {
101
101
  { title: 'Lodash(工具库)', value: 'lodash' },
102
102
  { title: 'Day.js(日期处理)', value: 'dayjs' },
103
103
  { title: 'Tailwind CSS(原子化 CSS)', value: 'tailwind' },
104
- { title: 'mitt(事件总线)', value: 'mitt' }
104
+ { title: 'mitt(事件总线)', value: 'mitt' },
105
+ { title: 'HTTPS(mkcert)', value: 'https' }
105
106
  ]
106
107
  })
107
108
 
@@ -114,7 +115,7 @@ const pkgCommands = {
114
115
  }
115
116
 
116
117
  const extraPlugins = featureList?.filter(v =>
117
- ['vueuse', 'lodash', 'dayjs', 'tailwind', 'mitt'].includes(v)
118
+ ['vueuse', 'lodash', 'dayjs', 'tailwind', 'mitt', 'https'].includes(v)
118
119
  ) || []
119
120
 
120
121
  // 询问是否开启自动路由
@@ -131,6 +132,8 @@ const pkgCommands = {
131
132
  autoRoute = enableAutoRoute
132
133
  }
133
134
 
135
+ const enableHttps = featureList?.includes('https') || false
136
+
134
137
  // 3️⃣ 是否立即运行 dev
135
138
  const { runDev } = await prompts({
136
139
  type: 'select',
@@ -266,6 +269,7 @@ for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
266
269
  optionalDeps['postcss'] = '^8.5.8'
267
270
  }
268
271
  if(extraPlugins.includes('mitt')) optionalDeps['mitt'] = '^3.0.1'
272
+ if(enableHttps) optionalDeps['vite-plugin-mkcert'] = '^1.17.10'
269
273
  if(autoRoute) optionalDeps['vite-plugin-pages'] = '^0.33.3'
270
274
 
271
275
  let depsStr = ''
@@ -278,23 +282,66 @@ for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
278
282
  .replace('__PROJECT_NAME__', projectName)
279
283
  .replace('__OPTIONAL_DEP__', depsStr)
280
284
 
285
+ // ⭐ 新增逻辑
286
+ let pkgObj = JSON.parse(pkg)
287
+
288
+ if(pkgManager === 'pnpm' && features.ui.includes('vant')) {
289
+ pkgObj.pnpm = {
290
+ overrides: {
291
+ "@vant/use": "^1.0.0",
292
+ "@vant/popperjs": "^1.0.0"
293
+ }
294
+ }
295
+ }
296
+
297
+ pkg = JSON.stringify(pkgObj, null, 2)
298
+
281
299
  fs.writeFileSync(path.join(targetDir, 'package.json'), pkg)
282
300
  fs.unlinkSync(pkgTpl)
283
301
  }
284
302
 
285
- // 8️⃣ 配置自动路由
286
- if(autoRoute) {
287
- const viteConfigPath = path.join(targetDir, `vite.config.${language === 'ts' ? 'ts' : 'js'}`)
288
- if(fs.existsSync(viteConfigPath)) {
289
- let viteConfig = fs.readFileSync(viteConfigPath, 'utf-8')
303
+ // 8️⃣ 配置 vite.config.js / vite.config.ts(自动路由 + HTTPS)
304
+ const viteConfigPath = path.join(
305
+ targetDir,
306
+ `vite.config.${language === 'ts' ? 'ts' : 'js'}`
307
+ )
308
+
309
+ if(fs.existsSync(viteConfigPath)) {
310
+ let viteConfig = fs.readFileSync(viteConfigPath, 'utf-8')
311
+
312
+ // ===== mkcert 插件 =====
313
+ if(enableHttps) {
314
+ if(!viteConfig.includes("vite-plugin-mkcert")) {
315
+ viteConfig = viteConfig.replace(
316
+ /(import .*?from .*?\n)/,
317
+ `$1import mkcert from 'vite-plugin-mkcert'\n`
318
+ )
319
+ }
320
+
321
+ if(!viteConfig.includes("mkcert(")) {
322
+ viteConfig = viteConfig.replace(
323
+ /plugins:\s*\[/,
324
+ `plugins: [
325
+ mkcert(),`
326
+ )
327
+ }
328
+ }
329
+
330
+ // ===== 自动路由 =====
331
+ if(autoRoute) {
290
332
  if(!viteConfig.includes("import fs from 'fs'")) {
291
333
  viteConfig = `import fs from 'fs'\n${viteConfig}`
292
334
  }
293
- // 确保顶部 import Pages
294
335
  if(!viteConfig.includes("import Pages from 'vite-plugin-pages'")) {
295
- viteConfig = viteConfig.replace(/(import .*?from .*?\n)/, `$1import Pages from 'vite-plugin-pages'\n`)
336
+ viteConfig = viteConfig.replace(
337
+ /(import .*?from .*?\n)/,
338
+ `$1import Pages from 'vite-plugin-pages'\n`
339
+ )
296
340
  }
297
- viteConfig = viteConfig.replace(/plugins:\s*\[/, `plugins: [
341
+ if(!viteConfig.includes("Pages({")) {
342
+ viteConfig = viteConfig.replace(
343
+ /plugins:\s*\[/,
344
+ `plugins: [
298
345
  Pages({
299
346
  dirs: 'src/views',
300
347
  extensions: ['vue'],
@@ -314,33 +361,13 @@ for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
314
361
  }
315
362
  return { ...route }
316
363
  }
317
- }),`)
318
- fs.writeFileSync(viteConfigPath, viteConfig)
319
- }
320
-
321
- // 创建 Home/meta.json
322
- const homeMetaPath = path.join(targetDir, 'src/views/home/meta.json')
323
- if(!fs.existsSync(homeMetaPath)) {
324
- fs.writeFileSync(homeMetaPath, JSON.stringify({ title: '首页' }, null, 2))
325
- }
326
- if(language === 'ts') {
327
- // 生成 types 目录
328
- const typesDir = path.join(targetDir, 'src/types')
329
- if(!fs.existsSync(typesDir)) fs.mkdirSync(typesDir, { recursive: true })
330
-
331
- // 创建 vite-plugin-pages.d.ts
332
- const vitePagesDtsPath = path.join(typesDir, 'vite-plugin-pages.d.ts')
333
- const vitePagesDtsContent = `declare module '~pages' {
334
- import type { RouteRecordRaw } from 'vue-router'
335
- const routes: RouteRecordRaw[]
336
- export default routes
337
- }
338
- `
339
- fs.writeFileSync(vitePagesDtsPath, vitePagesDtsContent)
364
+ }),`
365
+ )
366
+ }
340
367
  }
341
368
 
369
+ fs.writeFileSync(viteConfigPath, viteConfig)
342
370
  }
343
-
344
371
  // 9️⃣ 替换 router/index.js
345
372
  if(features.router) {
346
373
  const routerIndexPath = path.join(targetDir, `src/router/index.${language === 'ts' ? 'ts' : 'js'}`)
@@ -398,6 +425,9 @@ export default createRouter({
398
425
  // 1️⃣1️⃣ 运行 dev
399
426
  if(runDev) {
400
427
  console.log('🚀 启动开发服务器...')
428
+ if(enableHttps) {
429
+ console.log('🔐 首次启用 HTTPS 会自动生成证书,请稍等...')
430
+ }
401
431
  execSync(pkgCommands[pkgManager].dev, {
402
432
  cwd: targetDir,
403
433
  stdio: 'inherit'
@@ -405,7 +435,10 @@ export default createRouter({
405
435
  } else {
406
436
  console.log(`\n✅ 项目创建完成`)
407
437
  console.log(`👉 cd ${projectName}`)
408
- console.log(`👉 ${pkgCommands[pkgManager].dev}\n`)
438
+ console.log(`👉 ${pkgCommands[pkgManager].dev}`)
439
+ if(enableHttps) {
440
+ console.log('🔐 首次启用 HTTPS 会自动生成证书,请稍等...\n')
441
+ }
409
442
  }
410
443
  })()
411
444
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-vite-vue",
3
- "version": "1.5.7",
3
+ "version": "1.6.1",
4
4
  "description": "基于Vite+Vue3创建基础项目模板",
5
5
  "main": "index.js",
6
6
  "author": "YwaiX",
@@ -21,6 +21,7 @@
21
21
  - 🎨 可选集成 Tailwind CSS(通过 postcss 配置)
22
22
  - 🟢 支持多种包管理器:npm / pnpm,可根据环境自动识别并使用
23
23
  - 🔔 可选集成 Mitt(轻量事件总线,实现组件间解耦通信)
24
+ - 🛡️ 可选集成 mkcert 插件,实现本地 HTTPS 开发环境
24
25
 
25
26
  ---
26
27
 
@@ -36,6 +37,7 @@
36
37
  🧰 VueUse · Lodash · Day.js
37
38
  🎨 Tailwind CSS
38
39
  🔔 Mitt
40
+ 🛡️ mkcert (本地 HTTPS)
39
41
 
40
42
  ---
41
43
 
@@ -230,6 +232,34 @@ console.log(route.params.id)
230
232
  console.log(route.params.name)
231
233
  ```
232
234
 
235
+ ### ✅ meta.json 自动注入路由
236
+
237
+ 在每个页面目录下可以新增一个 `meta.json` 文件:
238
+
239
+ ```text
240
+ src/views/home/
241
+ ├─ index.vue
242
+ └─ meta.json
243
+ ```
244
+
245
+ #### 示例:
246
+
247
+ ```json
248
+ {
249
+ "name": "首页",
250
+ "orderMenu": 1
251
+ }
252
+ ```
253
+
254
+ 👉 脚手架会自动读取该文件,并注入到对应路由的 `meta` 属性中:
255
+
256
+ ```js
257
+ route.meta = {
258
+ name: "首页",
259
+ orderMenu: 1
260
+ }
261
+ ```
262
+
233
263
  ---
234
264
 
235
265
  ### 4️⃣ 页面内容与样式
@@ -21,6 +21,7 @@
21
21
  - 🎨 可选集成 Tailwind CSS(通过 postcss 配置)
22
22
  - 🟢 支持多种包管理器:npm / pnpm,可根据环境自动识别并使用
23
23
  - 🔔 可选集成 Mitt(轻量事件总线,实现组件间解耦通信)
24
+ - 🛡️ 可选集成 mkcert 插件,实现本地 HTTPS 开发环境
24
25
 
25
26
  ---
26
27
 
@@ -36,6 +37,7 @@
36
37
  🧰 VueUse · Lodash · Day.js
37
38
  🎨 Tailwind CSS
38
39
  🔔 Mitt
40
+ 🛡️ mkcert (本地 HTTPS)
39
41
 
40
42
  ---
41
43
 
@@ -230,6 +232,34 @@ console.log(route.params.id)
230
232
  console.log(route.params.name)
231
233
  ```
232
234
 
235
+ ### ✅ meta.json 自动注入路由
236
+
237
+ 在每个页面目录下可以新增一个 `meta.json` 文件:
238
+
239
+ ```text
240
+ src/views/home/
241
+ ├─ index.vue
242
+ └─ meta.json
243
+ ```
244
+
245
+ #### 示例:
246
+
247
+ ```json
248
+ {
249
+ "name": "首页",
250
+ "orderMenu": 1
251
+ }
252
+ ```
253
+
254
+ 👉 脚手架会自动读取该文件,并注入到对应路由的 `meta` 属性中:
255
+
256
+ ```js
257
+ route.meta = {
258
+ name: "首页",
259
+ orderMenu: 1
260
+ }
261
+ ```
262
+
233
263
  ---
234
264
 
235
265
  ### 4️⃣ 页面内容与样式