create-vite-vue 1.5.7 → 1.6.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/README.md +2 -0
- package/bin/index.js +55 -36
- package/package.json +1 -1
- package/template/base-js/README.md +2 -0
- package/template/base-ts/README.md +2 -0
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
|
|
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 = ''
|
|
@@ -282,19 +286,48 @@ for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
|
|
282
286
|
fs.unlinkSync(pkgTpl)
|
|
283
287
|
}
|
|
284
288
|
|
|
285
|
-
// 8️⃣
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
289
|
+
// 8️⃣ 配置 vite.config.js / vite.config.ts(自动路由 + HTTPS)
|
|
290
|
+
const viteConfigPath = path.join(
|
|
291
|
+
targetDir,
|
|
292
|
+
`vite.config.${language === 'ts' ? 'ts' : 'js'}`
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
if(fs.existsSync(viteConfigPath)) {
|
|
296
|
+
let viteConfig = fs.readFileSync(viteConfigPath, 'utf-8')
|
|
297
|
+
|
|
298
|
+
// ===== mkcert 插件 =====
|
|
299
|
+
if(enableHttps) {
|
|
300
|
+
if(!viteConfig.includes("vite-plugin-mkcert")) {
|
|
301
|
+
viteConfig = viteConfig.replace(
|
|
302
|
+
/(import .*?from .*?\n)/,
|
|
303
|
+
`$1import mkcert from 'vite-plugin-mkcert'\n`
|
|
304
|
+
)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if(!viteConfig.includes("mkcert(")) {
|
|
308
|
+
viteConfig = viteConfig.replace(
|
|
309
|
+
/plugins:\s*\[/,
|
|
310
|
+
`plugins: [
|
|
311
|
+
mkcert(),`
|
|
312
|
+
)
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// ===== 自动路由 =====
|
|
317
|
+
if(autoRoute) {
|
|
290
318
|
if(!viteConfig.includes("import fs from 'fs'")) {
|
|
291
319
|
viteConfig = `import fs from 'fs'\n${viteConfig}`
|
|
292
320
|
}
|
|
293
|
-
// 确保顶部 import Pages
|
|
294
321
|
if(!viteConfig.includes("import Pages from 'vite-plugin-pages'")) {
|
|
295
|
-
viteConfig = viteConfig.replace(
|
|
322
|
+
viteConfig = viteConfig.replace(
|
|
323
|
+
/(import .*?from .*?\n)/,
|
|
324
|
+
`$1import Pages from 'vite-plugin-pages'\n`
|
|
325
|
+
)
|
|
296
326
|
}
|
|
297
|
-
viteConfig
|
|
327
|
+
if(!viteConfig.includes("Pages({")) {
|
|
328
|
+
viteConfig = viteConfig.replace(
|
|
329
|
+
/plugins:\s*\[/,
|
|
330
|
+
`plugins: [
|
|
298
331
|
Pages({
|
|
299
332
|
dirs: 'src/views',
|
|
300
333
|
extensions: ['vue'],
|
|
@@ -314,33 +347,13 @@ for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
|
|
|
314
347
|
}
|
|
315
348
|
return { ...route }
|
|
316
349
|
}
|
|
317
|
-
}),`
|
|
318
|
-
|
|
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)
|
|
350
|
+
}),`
|
|
351
|
+
)
|
|
352
|
+
}
|
|
340
353
|
}
|
|
341
354
|
|
|
355
|
+
fs.writeFileSync(viteConfigPath, viteConfig)
|
|
342
356
|
}
|
|
343
|
-
|
|
344
357
|
// 9️⃣ 替换 router/index.js
|
|
345
358
|
if(features.router) {
|
|
346
359
|
const routerIndexPath = path.join(targetDir, `src/router/index.${language === 'ts' ? 'ts' : 'js'}`)
|
|
@@ -398,6 +411,9 @@ export default createRouter({
|
|
|
398
411
|
// 1️⃣1️⃣ 运行 dev
|
|
399
412
|
if(runDev) {
|
|
400
413
|
console.log('🚀 启动开发服务器...')
|
|
414
|
+
if(enableHttps) {
|
|
415
|
+
console.log('🔐 首次启用 HTTPS 会自动生成证书,请稍等...')
|
|
416
|
+
}
|
|
401
417
|
execSync(pkgCommands[pkgManager].dev, {
|
|
402
418
|
cwd: targetDir,
|
|
403
419
|
stdio: 'inherit'
|
|
@@ -405,7 +421,10 @@ export default createRouter({
|
|
|
405
421
|
} else {
|
|
406
422
|
console.log(`\n✅ 项目创建完成`)
|
|
407
423
|
console.log(`👉 cd ${projectName}`)
|
|
408
|
-
console.log(`👉 ${pkgCommands[pkgManager].dev}
|
|
424
|
+
console.log(`👉 ${pkgCommands[pkgManager].dev}`)
|
|
425
|
+
if(enableHttps) {
|
|
426
|
+
console.log('🔐 首次启用 HTTPS 会自动生成证书,请稍等...\n')
|
|
427
|
+
}
|
|
409
428
|
}
|
|
410
429
|
})()
|
|
411
430
|
|
package/package.json
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
|
|
|
@@ -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
|
|