befly-vite 1.5.1 → 1.5.3

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.
Files changed (2) hide show
  1. package/index.js +38 -5
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -6,10 +6,28 @@ import vue from "@vitejs/plugin-vue";
6
6
  import AutoImport from "unplugin-auto-import/vite";
7
7
  import { TDesignResolver } from "unplugin-vue-components/resolvers";
8
8
  import Components from "unplugin-vue-components/vite";
9
+ import analyzer from "vite-bundle-analyzer";
10
+ import VueDevTools from "vite-plugin-vue-devtools";
9
11
  import { defineConfig, mergeConfig } from "vite";
10
12
  import { VueRouterAutoImports } from "vue-router/unplugin";
11
13
  import VueRouter from "vue-router/vite";
12
14
 
15
+ function parseBooleanEnv(value, defaultValue) {
16
+ if (value === undefined || value === null || value === "") {
17
+ return defaultValue;
18
+ }
19
+
20
+ const normalized = String(value).trim().toLowerCase();
21
+ if (normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on") {
22
+ return true;
23
+ }
24
+ if (normalized === "0" || normalized === "false" || normalized === "no" || normalized === "off") {
25
+ return false;
26
+ }
27
+
28
+ return defaultValue;
29
+ }
30
+
13
31
  /**
14
32
  * 创建路由插件配置
15
33
  */
@@ -86,6 +104,17 @@ function createComponentsPlugin() {
86
104
  });
87
105
  }
88
106
 
107
+ function createDevToolsPlugin() {
108
+ return VueDevTools();
109
+ }
110
+
111
+ function createAnalyzerPlugin() {
112
+ return analyzer({
113
+ analyzerMode: "server",
114
+ openAnalyzer: false
115
+ });
116
+ }
117
+
89
118
  /**
90
119
  * 创建 Befly Vite 配置
91
120
  * @param {Object} options - 配置选项
@@ -102,17 +131,21 @@ export function createBeflyViteConfig(options = {}) {
102
131
  const appRoot = root || process.cwd();
103
132
 
104
133
  const routesFolders = scanViews(appRoot);
134
+ const enableDevTools = parseBooleanEnv(process.env.VITE_ENABLE_DEVTOOLS, false);
135
+ const enableAnalyzer = parseBooleanEnv(process.env.VITE_ENABLE_ANALYZER, false);
105
136
 
106
137
  /** @type {import('vite').Plugin[]} */
107
138
  const plugins = [];
108
139
  plugins.push(createRouterPlugin({ routesFolders: routesFolders }));
109
140
  plugins.push(createVuePlugin());
110
- // plugins.push(createDevToolsPlugin());
141
+ if (enableDevTools) {
142
+ plugins.push(createDevToolsPlugin());
143
+ }
111
144
  plugins.push(createAutoImportPlugin({ resolvers: resolvers }));
112
145
  plugins.push(createComponentsPlugin({ resolvers: resolvers }));
113
- // if (enableAnalyzer) {
114
- // plugins.push(createAnalyzerPlugin());
115
- // }
146
+ if (enableAnalyzer) {
147
+ plugins.push(createAnalyzerPlugin());
148
+ }
116
149
 
117
150
  const baseConfig = defineConfig({
118
151
  base: "./",
@@ -159,7 +192,7 @@ export function scanViews(appRoot = process.cwd()) {
159
192
  if (existsSync(appViewsPath)) {
160
193
  routesFolders.push({
161
194
  src: realpathSync(appViewsPath),
162
- path: "",
195
+ path: "app/",
163
196
  exclude: ["**/components/**"]
164
197
  });
165
198
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "befly-vite",
3
- "version": "1.5.1",
4
- "gitHead": "c71ecec269032dcc0aa8ca995da4918f99f5ee0e",
3
+ "version": "1.5.3",
4
+ "gitHead": "aed5c2a383bfcc1d8489ee880bca3f36bc2cbd28",
5
5
  "private": false,
6
6
  "description": "Befly Vite 配置预设和插件集合",
7
7
  "keywords": [