befly-vite 1.7.11 → 1.7.12
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 +14 -38
- package/index.js +2 -22
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -74,16 +74,15 @@ export default createBeflyViteConfig();
|
|
|
74
74
|
|
|
75
75
|
1. `vue-router/vite` 路由扫描插件
|
|
76
76
|
2. `@vitejs/plugin-vue`
|
|
77
|
-
3. `unplugin-
|
|
78
|
-
4. `
|
|
79
|
-
5.
|
|
80
|
-
6. `server.
|
|
81
|
-
7. `
|
|
82
|
-
8. `build.
|
|
83
|
-
9. `build.
|
|
84
|
-
10. `
|
|
85
|
-
11.
|
|
86
|
-
12. 默认 CSS 浏览器基线:Chrome 107 / Edge 107 / Firefox 104 / Safari 16.0
|
|
77
|
+
3. `unplugin-vue-components`
|
|
78
|
+
4. `@` 指向项目 `src`
|
|
79
|
+
5. `server.open = false`
|
|
80
|
+
6. `server.hmr = true`
|
|
81
|
+
7. `build.outDir = "dist"`
|
|
82
|
+
8. `build.assetsDir = "assets"`
|
|
83
|
+
9. `build.cssMinify = "lightningcss"`
|
|
84
|
+
10. `css.transformer = "lightningcss"`
|
|
85
|
+
11. 默认 CSS 浏览器基线:Chrome 107 / Edge 107 / Firefox 104 / Safari 16.0
|
|
87
86
|
|
|
88
87
|
### 参数说明
|
|
89
88
|
|
|
@@ -92,7 +91,7 @@ export default createBeflyViteConfig();
|
|
|
92
91
|
| `root` | `string` | `process.cwd()` | 项目根目录,用于解析 `src`、扫描 `views` 和生成别名 |
|
|
93
92
|
| `devtool` | `boolean` | `false` | 是否启用 `vite-plugin-vue-devtools` |
|
|
94
93
|
| `analyzer` | `boolean` | `false` | 是否启用打包分析,并输出到 `<root>/temp/analyzer` |
|
|
95
|
-
| `resolvers` | `Object \| Object[]` | `undefined` |
|
|
94
|
+
| `resolvers` | `Object \| Object[]` | `undefined` | 追加到组件自动注册中的自定义 resolver |
|
|
96
95
|
| `manualChunks` | `Function \| Object` | `undefined` | 便捷写入 `build.rolldownOptions.output.manualChunks` |
|
|
97
96
|
| `viteConfig` | `Object` | `{}` | 最终合并到默认配置上的 Vite 原生配置 |
|
|
98
97
|
|
|
@@ -154,8 +153,7 @@ export default createBeflyViteConfig({
|
|
|
154
153
|
|
|
155
154
|
如果项目还想增加额外 resolver,可以通过 `resolvers` 追加。它会同时追加到:
|
|
156
155
|
|
|
157
|
-
1. `unplugin-
|
|
158
|
-
2. `unplugin-vue-components`
|
|
156
|
+
1. `unplugin-vue-components`
|
|
159
157
|
|
|
160
158
|
```javascript
|
|
161
159
|
import { createBeflyViteConfig } from "befly-vite";
|
|
@@ -458,31 +456,9 @@ console.log(routesFolders);
|
|
|
458
456
|
];
|
|
459
457
|
```
|
|
460
458
|
|
|
461
|
-
##
|
|
459
|
+
## 组件自动注册规则
|
|
462
460
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
默认会对以下文件启用自动导入:
|
|
466
|
-
|
|
467
|
-
```text
|
|
468
|
-
src/**/*.vue
|
|
469
|
-
src/**/*.js
|
|
470
|
-
```
|
|
471
|
-
|
|
472
|
-
默认自动导入内容:
|
|
473
|
-
|
|
474
|
-
1. `vue`
|
|
475
|
-
2. `pinia`
|
|
476
|
-
3. `vue-router` 的 auto imports
|
|
477
|
-
4. 默认 TDesign resolver
|
|
478
|
-
5. 你额外传入的 `resolvers`
|
|
479
|
-
|
|
480
|
-
默认扫描目录:
|
|
481
|
-
|
|
482
|
-
1. `src/utils`
|
|
483
|
-
2. `src/plugins`
|
|
484
|
-
3. `src/config`
|
|
485
|
-
4. `src/hooks`
|
|
461
|
+
`befly-vite` 现在只负责 Vue 组件自动注册,不再自动导入 Vue、Pinia、Vue Router API。页面和组件里用到这些 API 时,需要显式 `import`。
|
|
486
462
|
|
|
487
463
|
### Components
|
|
488
464
|
|
|
@@ -500,7 +476,7 @@ src/**/*.js
|
|
|
500
476
|
说明:
|
|
501
477
|
|
|
502
478
|
1. `src/components` 会被作为本地组件目录扫描
|
|
503
|
-
2.
|
|
479
|
+
2. `befly-vite` 只自动注册组件;Vue、Pinia、Vue Router API 仍需按项目规范手动导入
|
|
504
480
|
|
|
505
481
|
## Layouts
|
|
506
482
|
|
package/index.js
CHANGED
|
@@ -3,13 +3,11 @@ import { join } from "node:path";
|
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
|
|
5
5
|
import vue from "@vitejs/plugin-vue";
|
|
6
|
-
import AutoImport from "unplugin-auto-import/vite";
|
|
7
6
|
import { TDesignResolver } from "unplugin-vue-components/resolvers";
|
|
8
7
|
import Components from "unplugin-vue-components/vite";
|
|
9
8
|
import { defineConfig, mergeConfig } from "vite";
|
|
10
9
|
import bundleAnalyzer from "vite-bundle-analyzer";
|
|
11
10
|
import VueDevTools from "vite-plugin-vue-devtools";
|
|
12
|
-
import { VueRouterAutoImports } from "vue-router/unplugin";
|
|
13
11
|
import VueRouter from "vue-router/vite";
|
|
14
12
|
|
|
15
13
|
/**
|
|
@@ -58,23 +56,6 @@ function normalizeResolvers(resolvers) {
|
|
|
58
56
|
return [resolvers];
|
|
59
57
|
}
|
|
60
58
|
|
|
61
|
-
/**
|
|
62
|
-
* 创建自动导入插件配置
|
|
63
|
-
*/
|
|
64
|
-
function createAutoImportPlugin(options = {}) {
|
|
65
|
-
const { resolvers } = options;
|
|
66
|
-
|
|
67
|
-
return AutoImport({
|
|
68
|
-
// 只给 admin 自身源码做自动导入;addon 视图强制手动导入
|
|
69
|
-
include: [/[\\/]src[\\/].*\.(vue|js)$/],
|
|
70
|
-
imports: ["vue", "pinia", VueRouterAutoImports],
|
|
71
|
-
resolvers: [createTDesignResolver(), ...normalizeResolvers(resolvers)],
|
|
72
|
-
dts: false,
|
|
73
|
-
dirs: ["src/utils", "src/plugins", "src/config", "src/hooks"],
|
|
74
|
-
vueTemplate: true
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
59
|
function resolveTDesignIcon(componentName) {
|
|
79
60
|
if (componentName === "Icon" || componentName === "IconFont" || componentName.endsWith("Icon")) {
|
|
80
61
|
return {
|
|
@@ -85,7 +66,7 @@ function resolveTDesignIcon(componentName) {
|
|
|
85
66
|
}
|
|
86
67
|
|
|
87
68
|
/**
|
|
88
|
-
*
|
|
69
|
+
* 创建组件自动注册插件配置
|
|
89
70
|
*/
|
|
90
71
|
function createComponentsPlugin(options = {}) {
|
|
91
72
|
const { resolvers } = options;
|
|
@@ -135,7 +116,7 @@ function createCssCompatConfig(viteConfig) {
|
|
|
135
116
|
* @param {string} options.root - 项目根目录(可选)
|
|
136
117
|
* @param {boolean} options.devtool - 是否启用 vite-plugin-vue-devtools(可选,默认 false)
|
|
137
118
|
* @param {boolean} options.analyzer - 是否启用 vite-bundle-analyzer(可选,默认 false)
|
|
138
|
-
* @param {Object|Object[]} options.resolvers -
|
|
119
|
+
* @param {Object|Object[]} options.resolvers - 自定义组件 resolvers(可选)
|
|
139
120
|
* @param {Function|Object} options.manualChunks - 便捷分包配置,会写入 build.rolldownOptions.output.manualChunks(可选)
|
|
140
121
|
* @param {Object} options.viteConfig - 用户自定义配置(可选)
|
|
141
122
|
* @returns {Object} Vite 配置对象
|
|
@@ -163,7 +144,6 @@ export function createBeflyViteConfig(options = {}) {
|
|
|
163
144
|
if (devtool) {
|
|
164
145
|
plugins.push(VueDevTools());
|
|
165
146
|
}
|
|
166
|
-
plugins.push(createAutoImportPlugin({ resolvers: resolvers }));
|
|
167
147
|
plugins.push(createComponentsPlugin({ resolvers: resolvers }));
|
|
168
148
|
if (analyzer) {
|
|
169
149
|
plugins.push(createAnalyzerPlugin(appRoot));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly-vite",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.12",
|
|
4
4
|
"gitHead": "282f7accca9c8d55956a5490c0365cce4a1ad90d",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Befly Vite 配置预设和插件集合",
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@vitejs/plugin-vue": "^6.0.7",
|
|
41
41
|
"sass": "^1.100.0",
|
|
42
|
-
"unplugin-auto-import": "^21.0.0",
|
|
43
42
|
"unplugin-vue-components": "^32.1.0",
|
|
44
43
|
"vite": "^8.0.14",
|
|
45
44
|
"vite-bundle-analyzer": "^1.3.8",
|