create-vite-vue 2.0.0 → 2.1.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 +7 -8
- package/lib/features.js +18 -6
- package/lib/package.js +12 -18
- package/lib/plugins/index.js +9 -9
- package/package.json +8 -1
- package/.vscode/settings.json +0 -22
package/bin/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { fileURLToPath } from 'url'
|
|
|
6
6
|
|
|
7
7
|
// === 导入模块 ===
|
|
8
8
|
import { cleanMainFile } from '../lib/cleanMain.js'
|
|
9
|
-
import {
|
|
9
|
+
import { parsePlugins } from '../lib/features.js'
|
|
10
10
|
import { generatePackageJson } from '../lib/package.js'
|
|
11
11
|
import { setupPlugins } from '../lib/plugins/index.js'
|
|
12
12
|
import { askAutoRoute, askRunDev, chooseFeatures, chooseLanguage, getProjectName } from '../lib/prompts.js'
|
|
@@ -32,13 +32,12 @@ const requiredVersion = '22.19.0'
|
|
|
32
32
|
// 4. 选择功能
|
|
33
33
|
const featureList = await chooseFeatures()
|
|
34
34
|
|
|
35
|
-
// 5.
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const enableHttps = featureList.includes('https') || false
|
|
35
|
+
// 5. 解析插件
|
|
36
|
+
const plugins = parsePlugins(featureList)
|
|
37
|
+
const enableHttps = plugins.https
|
|
39
38
|
|
|
40
39
|
// 6. 询问自动路由
|
|
41
|
-
const autoRoute = await askAutoRoute(
|
|
40
|
+
const autoRoute = await askAutoRoute(plugins.router)
|
|
42
41
|
|
|
43
42
|
// 7. 询问是否运行 dev
|
|
44
43
|
const pkgManager = detectPackageManager()
|
|
@@ -55,7 +54,7 @@ const requiredVersion = '22.19.0'
|
|
|
55
54
|
await updateIndexHtml(projectName, targetDir)
|
|
56
55
|
|
|
57
56
|
// 10. 配置插件,并获取已使用的占位符
|
|
58
|
-
const unusedPlaceholders = await setupPlugins(
|
|
57
|
+
const unusedPlaceholders = await setupPlugins(plugins, {
|
|
59
58
|
language,
|
|
60
59
|
targetDir,
|
|
61
60
|
autoRoute,
|
|
@@ -67,7 +66,7 @@ const requiredVersion = '22.19.0'
|
|
|
67
66
|
await cleanMainFile(language, targetDir, unusedPlaceholders)
|
|
68
67
|
|
|
69
68
|
// 12. 生成 package.json
|
|
70
|
-
await generatePackageJson(projectName,
|
|
69
|
+
await generatePackageJson(projectName, plugins, autoRoute, enableHttps, language, targetDir, pkgManager)
|
|
71
70
|
|
|
72
71
|
// 13. 安装依赖
|
|
73
72
|
console.log('\n📦 正在安装依赖...')
|
package/lib/features.js
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
// lib/features.js
|
|
2
|
-
export function
|
|
2
|
+
export function parsePlugins (featureList) {
|
|
3
3
|
return {
|
|
4
|
+
// 核心插件
|
|
4
5
|
router: featureList.includes('router'),
|
|
5
6
|
pinia: featureList.includes('pinia'),
|
|
6
7
|
axios: featureList.includes('axios'),
|
|
7
|
-
ui: featureList.filter(v => ['element', 'vant'].includes(v))
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
// UI 插件
|
|
10
|
+
elementPlus: featureList.includes('element'),
|
|
11
|
+
vant: featureList.includes('vant'),
|
|
12
|
+
|
|
13
|
+
// 工具插件
|
|
14
|
+
vueuse: featureList.includes('vueuse'),
|
|
15
|
+
lodash: featureList.includes('lodash'),
|
|
16
|
+
dayjs: featureList.includes('dayjs'),
|
|
17
|
+
mitt: featureList.includes('mitt'),
|
|
18
|
+
|
|
19
|
+
// 样式插件
|
|
20
|
+
tailwind: featureList.includes('tailwind'),
|
|
21
|
+
|
|
22
|
+
// 开发工具
|
|
23
|
+
https: featureList.includes('https')
|
|
24
|
+
}
|
|
13
25
|
}
|
package/lib/package.js
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
import { existsSync } from 'fs'
|
|
3
3
|
import fs from 'fs/promises'
|
|
4
4
|
import path from 'path'
|
|
5
|
-
|
|
6
|
-
export async function generatePackageJson (projectName, features, extraPlugins, autoRoute, enableHttps, language, targetDir, pkgManager) {
|
|
5
|
+
export async function generatePackageJson (projectName, plugins, autoRoute, enableHttps, language, targetDir, pkgManager) {
|
|
7
6
|
const pkgPath = path.join(targetDir, 'package.json')
|
|
8
7
|
|
|
9
8
|
if(!existsSync(pkgPath)) {
|
|
@@ -12,33 +11,31 @@ export async function generatePackageJson (projectName, features, extraPlugins,
|
|
|
12
11
|
|
|
13
12
|
let pkgContent = await fs.readFile(pkgPath, 'utf-8')
|
|
14
13
|
|
|
15
|
-
// 收集可选依赖
|
|
16
14
|
const optionalDeps = {}
|
|
17
15
|
|
|
18
|
-
if(
|
|
19
|
-
if(
|
|
16
|
+
if(plugins.router) optionalDeps['vue-router'] = '^5.0.3'
|
|
17
|
+
if(plugins.pinia) {
|
|
20
18
|
optionalDeps['pinia'] = '^3.0.4'
|
|
21
19
|
optionalDeps['pinia-plugin-persistedstate'] = '^4.7.1'
|
|
22
20
|
}
|
|
23
|
-
if(
|
|
24
|
-
if(
|
|
21
|
+
if(plugins.axios) optionalDeps['axios'] = '^1.13.6'
|
|
22
|
+
if(plugins.elementPlus) {
|
|
25
23
|
optionalDeps['element-plus'] = '^2.13.5'
|
|
26
24
|
optionalDeps['@element-plus/icons-vue'] = '^2.3.2'
|
|
27
25
|
}
|
|
28
|
-
if(
|
|
29
|
-
if(
|
|
30
|
-
if(
|
|
31
|
-
if(
|
|
32
|
-
if(
|
|
26
|
+
if(plugins.vant) optionalDeps['vant'] = '^4.9.22'
|
|
27
|
+
if(plugins.vueuse) optionalDeps['@vueuse/core'] = '^14.2.1'
|
|
28
|
+
if(plugins.dayjs) optionalDeps['dayjs'] = '^1.11.20'
|
|
29
|
+
if(plugins.lodash) optionalDeps['lodash'] = '^4.17.23'
|
|
30
|
+
if(plugins.tailwind) {
|
|
33
31
|
optionalDeps['tailwindcss'] = '^4.2.2'
|
|
34
32
|
optionalDeps['@tailwindcss/postcss'] = '^4.2.2'
|
|
35
33
|
optionalDeps['postcss'] = '^8.5.8'
|
|
36
34
|
}
|
|
37
|
-
if(
|
|
35
|
+
if(plugins.mitt) optionalDeps['mitt'] = '^3.0.1'
|
|
38
36
|
if(enableHttps) optionalDeps['vite-plugin-mkcert'] = '^1.17.10'
|
|
39
37
|
if(autoRoute) optionalDeps['vite-plugin-pages'] = '^0.33.3'
|
|
40
38
|
|
|
41
|
-
// 构建依赖字符串
|
|
42
39
|
const depsKeys = Object.keys(optionalDeps)
|
|
43
40
|
let depsStr = ''
|
|
44
41
|
|
|
@@ -46,15 +43,12 @@ export async function generatePackageJson (projectName, features, extraPlugins,
|
|
|
46
43
|
depsStr = ',\n' + depsKeys.map(k => ` "${k}": "${optionalDeps[k]}"`).join(',\n')
|
|
47
44
|
}
|
|
48
45
|
|
|
49
|
-
// 替换占位符
|
|
50
46
|
pkgContent = pkgContent.replace('__PROJECT_NAME__', projectName)
|
|
51
47
|
pkgContent = pkgContent.replace('__OPTIONAL_DEP__', depsStr)
|
|
52
48
|
|
|
53
|
-
// 解析并重新格式化 JSON
|
|
54
49
|
const pkgObj = JSON.parse(pkgContent)
|
|
55
50
|
|
|
56
|
-
|
|
57
|
-
if(pkgManager === 'pnpm' && features.ui.includes('vant')) {
|
|
51
|
+
if(pkgManager === 'pnpm' && plugins.vant) {
|
|
58
52
|
pkgObj.pnpm = { overrides: { "@vant/use": "^1.0.0", "@vant/popperjs": "^1.0.0" } }
|
|
59
53
|
}
|
|
60
54
|
|
package/lib/plugins/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { setupRouter } from './router.js'
|
|
|
8
8
|
import { setupTailwind } from './tailwind.js'
|
|
9
9
|
import { setupVant } from './vant.js'
|
|
10
10
|
|
|
11
|
-
export async function setupPlugins (
|
|
11
|
+
export async function setupPlugins (plugins, context) {
|
|
12
12
|
const { language, targetDir, autoRoute, enableHttps, __dirname } = context
|
|
13
13
|
|
|
14
14
|
// 收集未使用的占位符
|
|
@@ -19,8 +19,8 @@ export async function setupPlugins (features, extraPlugins, context) {
|
|
|
19
19
|
|
|
20
20
|
console.log('\n🔌 配置插件...')
|
|
21
21
|
|
|
22
|
-
// Router
|
|
23
|
-
if(
|
|
22
|
+
// Router
|
|
23
|
+
if(plugins.router) {
|
|
24
24
|
await setupRouter(language, targetDir, __dirname)
|
|
25
25
|
if(autoRoute) await setupAutoRoute(language, targetDir)
|
|
26
26
|
} else {
|
|
@@ -29,7 +29,7 @@ export async function setupPlugins (features, extraPlugins, context) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// Pinia
|
|
32
|
-
if(
|
|
32
|
+
if(plugins.pinia) {
|
|
33
33
|
await setupPinia(language, targetDir, __dirname)
|
|
34
34
|
} else {
|
|
35
35
|
unusedPlaceholders.import.push('/* __PINIA_IMPORT__ */')
|
|
@@ -37,7 +37,7 @@ export async function setupPlugins (features, extraPlugins, context) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// Element Plus
|
|
40
|
-
if(
|
|
40
|
+
if(plugins.elementPlus) {
|
|
41
41
|
await setupElementPlus(language, targetDir, __dirname)
|
|
42
42
|
} else {
|
|
43
43
|
unusedPlaceholders.import.push('/* __ELEMENT_IMPORT__ */')
|
|
@@ -45,7 +45,7 @@ export async function setupPlugins (features, extraPlugins, context) {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
// Vant
|
|
48
|
-
if(
|
|
48
|
+
if(plugins.vant) {
|
|
49
49
|
await setupVant(language, targetDir, __dirname)
|
|
50
50
|
} else {
|
|
51
51
|
unusedPlaceholders.import.push('/* __VANT_IMPORT__ */')
|
|
@@ -53,17 +53,17 @@ export async function setupPlugins (features, extraPlugins, context) {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
// Axios
|
|
56
|
-
if(
|
|
56
|
+
if(plugins.axios) {
|
|
57
57
|
await setupAxios(language, targetDir, __dirname)
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
// Tailwind
|
|
61
|
-
if(
|
|
61
|
+
if(plugins.tailwind) {
|
|
62
62
|
await setupTailwind(language, targetDir, __dirname)
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
// HTTPS
|
|
66
|
-
if(
|
|
66
|
+
if(plugins.https) {
|
|
67
67
|
await setupHttps(targetDir)
|
|
68
68
|
}
|
|
69
69
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-vite-vue",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "基于Vite+Vue3创建基础项目模板",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "YwaiX",
|
|
@@ -22,6 +22,13 @@
|
|
|
22
22
|
"pinia",
|
|
23
23
|
"axios"
|
|
24
24
|
],
|
|
25
|
+
"files": [
|
|
26
|
+
"bin/",
|
|
27
|
+
"lib/",
|
|
28
|
+
"template/",
|
|
29
|
+
"package.json",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
25
32
|
"dependencies": {
|
|
26
33
|
"prompts": "^2.4.2"
|
|
27
34
|
}
|
package/.vscode/settings.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"workbench.colorCustomizations": {
|
|
3
|
-
"activityBar.activeBackground": "#65c89b",
|
|
4
|
-
"activityBar.background": "#65c89b",
|
|
5
|
-
"activityBar.foreground": "#15202b",
|
|
6
|
-
"activityBar.inactiveForeground": "#15202b99",
|
|
7
|
-
"activityBarBadge.background": "#945bc4",
|
|
8
|
-
"activityBarBadge.foreground": "#e7e7e7",
|
|
9
|
-
"commandCenter.border": "#15202b99",
|
|
10
|
-
"sash.hoverBorder": "#65c89b",
|
|
11
|
-
"statusBar.background": "#42b883",
|
|
12
|
-
"statusBar.foreground": "#15202b",
|
|
13
|
-
"statusBarItem.hoverBackground": "#359268",
|
|
14
|
-
"statusBarItem.remoteBackground": "#42b883",
|
|
15
|
-
"statusBarItem.remoteForeground": "#15202b",
|
|
16
|
-
"titleBar.activeBackground": "#42b883",
|
|
17
|
-
"titleBar.activeForeground": "#15202b",
|
|
18
|
-
"titleBar.inactiveBackground": "#42b88399",
|
|
19
|
-
"titleBar.inactiveForeground": "#15202b99"
|
|
20
|
-
},
|
|
21
|
-
"peacock.color": "#42b883"
|
|
22
|
-
}
|