ebuilds-shared 0.2.1 → 0.2.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.
@@ -56,7 +56,6 @@ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
56
56
  var LIB_ROOT_DIR = _path2.default.resolve(__dirname, ".");
57
57
  var COMMON_ICONS_DIR = _path2.default.join(LIB_ROOT_DIR, "icons");
58
58
  function createUnoConfig(iconCollections) {
59
- console.log("createUnoConfig", COMMON_ICONS_DIR);
60
59
  return _unocss.defineConfig.call(void 0, {
61
60
  presets: [
62
61
  _unocss.presetUno.call(void 0, ),
@@ -194,7 +194,7 @@ var hmrCache = /* @__PURE__ */ new Map();
194
194
  var prevCache = /* @__PURE__ */ new Map();
195
195
  function createDescriptor(filename, source, {
196
196
  root,
197
- isProduction: isProduction2,
197
+ isProduction,
198
198
  sourceMap,
199
199
  compiler,
200
200
  template,
@@ -215,11 +215,11 @@ function createDescriptor(filename, source, {
215
215
  descriptor.id = componentIdGenerator(
216
216
  normalizedPath,
217
217
  source,
218
- isProduction2,
218
+ isProduction,
219
219
  getHash
220
220
  );
221
221
  } else {
222
- descriptor.id = getHash(normalizedPath + (isProduction2 ? source : ""));
222
+ descriptor.id = getHash(normalizedPath + (isProduction ? source : ""));
223
223
  }
224
224
  (hmr ? hmrCache : cache).set(filename, descriptor);
225
225
  return { descriptor, errors };
@@ -2005,7 +2005,7 @@ export default (sfc, props) => {
2005
2005
  }
2006
2006
  `;
2007
2007
  async function transformMain(code, filename, options, pluginContext, ssr, customElement) {
2008
- const { devServer, isProduction: isProduction2, devToolsEnabled } = options;
2008
+ const { devServer, isProduction, devToolsEnabled } = options;
2009
2009
  const prevDescriptor = getPrevDescriptor(filename);
2010
2010
  const { descriptor, errors } = createDescriptor(filename, code, options);
2011
2011
  if (_fs2.default.existsSync(filename)) {
@@ -2075,13 +2075,13 @@ async function transformMain(code, filename, options, pluginContext, ssr, custom
2075
2075
  if (hasScoped) {
2076
2076
  attachedProps.push([`__scopeId`, JSON.stringify(`data-v-${descriptor.id}`)]);
2077
2077
  }
2078
- if (devToolsEnabled || devServer && !isProduction2) {
2078
+ if (devToolsEnabled || devServer && !isProduction) {
2079
2079
  attachedProps.push([
2080
2080
  `__file`,
2081
- JSON.stringify(isProduction2 ? _path2.default.basename(filename) : filename)
2081
+ JSON.stringify(isProduction ? _path2.default.basename(filename) : filename)
2082
2082
  ]);
2083
2083
  }
2084
- if (devServer && devServer.config.server.hmr !== false && !ssr && !isProduction2) {
2084
+ if (devServer && devServer.config.server.hmr !== false && !ssr && !isProduction) {
2085
2085
  output.push(`_sfc_main.__hmrId = ${JSON.stringify(descriptor.id)}`);
2086
2086
  output.push(
2087
2087
  `typeof __VUE_HMR_RUNTIME__ !== 'undefined' && __VUE_HMR_RUNTIME__.createRecord(_sfc_main.__hmrId, _sfc_main)`
@@ -2522,7 +2522,7 @@ function vuePlugin(rawOptions = {}) {
2522
2522
  );
2523
2523
  }
2524
2524
  },
2525
- config(config) {
2525
+ config(config2) {
2526
2526
  const parseDefine = (v) => {
2527
2527
  try {
2528
2528
  return typeof v === "string" ? JSON.parse(v) : v;
@@ -2532,32 +2532,32 @@ function vuePlugin(rawOptions = {}) {
2532
2532
  };
2533
2533
  return {
2534
2534
  resolve: {
2535
- dedupe: _optionalChain([config, 'access', _68 => _68.build, 'optionalAccess', _69 => _69.ssr]) ? [] : ["vue"]
2535
+ dedupe: _optionalChain([config2, 'access', _68 => _68.build, 'optionalAccess', _69 => _69.ssr]) ? [] : ["vue"]
2536
2536
  },
2537
2537
  define: {
2538
- __VUE_OPTIONS_API__: _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'access', _70 => _70.value, 'access', _71 => _71.features, 'optionalAccess', _72 => _72.optionsAPI]), () => ( parseDefine(_optionalChain([config, 'access', _73 => _73.define, 'optionalAccess', _74 => _74.__VUE_OPTIONS_API__])))), () => ( true)),
2539
- __VUE_PROD_DEVTOOLS__: _nullishCoalesce((_optionalChain([options, 'access', _75 => _75.value, 'access', _76 => _76.features, 'optionalAccess', _77 => _77.prodDevtools]) || parseDefine(_optionalChain([config, 'access', _78 => _78.define, 'optionalAccess', _79 => _79.__VUE_PROD_DEVTOOLS__]))), () => ( false)),
2538
+ __VUE_OPTIONS_API__: _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'access', _70 => _70.value, 'access', _71 => _71.features, 'optionalAccess', _72 => _72.optionsAPI]), () => ( parseDefine(_optionalChain([config2, 'access', _73 => _73.define, 'optionalAccess', _74 => _74.__VUE_OPTIONS_API__])))), () => ( true)),
2539
+ __VUE_PROD_DEVTOOLS__: _nullishCoalesce((_optionalChain([options, 'access', _75 => _75.value, 'access', _76 => _76.features, 'optionalAccess', _77 => _77.prodDevtools]) || parseDefine(_optionalChain([config2, 'access', _78 => _78.define, 'optionalAccess', _79 => _79.__VUE_PROD_DEVTOOLS__]))), () => ( false)),
2540
2540
  __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: _nullishCoalesce((_optionalChain([options, 'access', _80 => _80.value, 'access', _81 => _81.features, 'optionalAccess', _82 => _82.prodHydrationMismatchDetails]) || parseDefine(
2541
- _optionalChain([config, 'access', _83 => _83.define, 'optionalAccess', _84 => _84.__VUE_PROD_HYDRATION_MISMATCH_DETAILS__])
2541
+ _optionalChain([config2, 'access', _83 => _83.define, 'optionalAccess', _84 => _84.__VUE_PROD_HYDRATION_MISMATCH_DETAILS__])
2542
2542
  )), () => ( false))
2543
2543
  },
2544
2544
  ssr: {
2545
2545
  // @ts-ignore -- config.legacy.buildSsrCjsExternalHeuristics will be removed in Vite 5
2546
- external: _optionalChain([config, 'access', _85 => _85.legacy, 'optionalAccess', _86 => _86.buildSsrCjsExternalHeuristics]) ? ["vue", "@vue/server-renderer"] : []
2546
+ external: _optionalChain([config2, 'access', _85 => _85.legacy, 'optionalAccess', _86 => _86.buildSsrCjsExternalHeuristics]) ? ["vue", "@vue/server-renderer"] : []
2547
2547
  }
2548
2548
  };
2549
2549
  },
2550
- configResolved(config) {
2550
+ configResolved(config2) {
2551
2551
  options.value = {
2552
2552
  ...options.value,
2553
- root: config.root,
2554
- sourceMap: config.command === "build" ? !!config.build.sourcemap : true,
2555
- cssDevSourcemap: _nullishCoalesce(_optionalChain([config, 'access', _87 => _87.css, 'optionalAccess', _88 => _88.devSourcemap]), () => ( false)),
2556
- isProduction: config.isProduction,
2557
- devToolsEnabled: !!(_optionalChain([options, 'access', _89 => _89.value, 'access', _90 => _90.features, 'optionalAccess', _91 => _91.prodDevtools]) || config.define.__VUE_PROD_DEVTOOLS__ || !config.isProduction)
2553
+ root: config2.root,
2554
+ sourceMap: config2.command === "build" ? !!config2.build.sourcemap : true,
2555
+ cssDevSourcemap: _nullishCoalesce(_optionalChain([config2, 'access', _87 => _87.css, 'optionalAccess', _88 => _88.devSourcemap]), () => ( false)),
2556
+ isProduction: config2.isProduction,
2557
+ devToolsEnabled: !!(_optionalChain([options, 'access', _89 => _89.value, 'access', _90 => _90.features, 'optionalAccess', _91 => _91.prodDevtools]) || config2.define.__VUE_PROD_DEVTOOLS__ || !config2.isProduction)
2558
2558
  };
2559
- const _warn = config.logger.warn;
2560
- config.logger.warn = (...args) => {
2559
+ const _warn = config2.logger.warn;
2560
+ config2.logger.warn = (...args) => {
2561
2561
  const msg = args[0];
2562
2562
  if (msg.match(
2563
2563
  /\[lightningcss\] '(deep|slotted|global)' is not recognized as a valid pseudo-/
@@ -2566,7 +2566,7 @@ function vuePlugin(rawOptions = {}) {
2566
2566
  }
2567
2567
  _warn(...args);
2568
2568
  };
2569
- transformCachedModule = config.command === "build" && options.value.sourceMap && config.build.watch != null;
2569
+ transformCachedModule = config2.command === "build" && options.value.sourceMap && config2.build.watch != null;
2570
2570
  },
2571
2571
  shouldTransformCachedModule({ id }) {
2572
2572
  if (transformCachedModule && parseVueRequest(id).query.vue) {
@@ -2823,96 +2823,121 @@ function server_default(devPort = 5e3, proxyConfig, baseUrl = "/") {
2823
2823
 
2824
2824
  // src/vite-config/build/index.ts
2825
2825
 
2826
- var isProduction = process.env.NODE_ENV === "production";
2827
- var build_default = {
2828
- /** 构建配置:设置 chunk 体积警告阈值为 1.5MB */
2829
- minify: isProduction ? "esbuild" : false,
2830
- // 禁用代码压缩
2831
- esbuild: isProduction ? {
2832
- drop: ["console", "debugger"],
2833
- // 生产环境移除 console/debugger
2834
- pure: ["console.log", "debugger"]
2835
- // 标记纯函数,进一步压缩
2836
- } : void 0,
2837
- sourcemap: isProduction ? "hidden-source-map" : true,
2838
- // 生成源映射文件
2839
- chunkSizeWarningLimit: 1500,
2840
- // 构建性能优化:启用缓存、指定目标环境
2841
- cacheDir: _path2.default.resolve(__dirname, "node_modules/.vite-cache"),
2842
- // 缓存构建产物
2843
- target: isProduction ? ["es2020", "chrome89", "safari14"] : "esnext",
2844
- // 生产环境适配主流浏览器
2845
- // Tree-Shaking 优化:强制开启生产环境 Tree-Shaking
2846
- treeshake: isProduction ? { moduleSideEffects: false } : true,
2847
- rollupOptions: {
2848
- output: {
2849
- /**
2850
- * 优化分包策略:
2851
- * 1. 大依赖(>100KB)单独分包
2852
- * 2. 小依赖合并到 vendor,减少 chunk 数量
2853
- * 3. 避免重复分包
2854
- */
2855
- manualChunks(id) {
2856
- if (id.includes("node_modules")) {
2857
- const moduleName = _optionalChain([id, 'access', _99 => _99.split, 'call', _100 => _100("node_modules/"), 'access', _101 => _101[1], 'optionalAccess', _102 => _102.split, 'call', _103 => _103("/"), 'access', _104 => _104[0]]) || "";
2858
- const largeDeps = ["lodash", "moment", "unocss", "axios", "echarts"];
2859
- if (largeDeps.includes(moduleName)) {
2860
- return `vendor-${moduleName}`;
2826
+ var _url = require('url');
2827
+ var __filename = _url.fileURLToPath.call(void 0, import.meta.url);
2828
+ var __dirname = _path2.default.dirname(__filename);
2829
+ var config = (isProduction) => {
2830
+ return {
2831
+ /**
2832
+ * 1. 压缩配置
2833
+ * 使用 esbuild 进行压缩,速度极快。
2834
+ * legalComments: 'none' 可以移除注释,进一步减小体积。
2835
+ */
2836
+ minify: isProduction ? "esbuild" : false,
2837
+ /** 2. Source Map 配置 */
2838
+ sourcemap: isProduction ? false : true,
2839
+ // 线上环境不生成 source map
2840
+ /** 3. 构建阈值优化 */
2841
+ chunkSizeWarningLimit: 1e3,
2842
+ // 建议调整为 1000KB,避免单个 chunk 过大影响首屏
2843
+ /** 4. 目标环境与缓存 */
2844
+ target: isProduction ? ["es2020", "chrome89", "edge88", "firefox78", "safari14"] : "esnext",
2845
+ /** 5. CSS 处理 */
2846
+ cssCodeSplit: true,
2847
+ // 启用 CSS 代码分割
2848
+ /** 6. 性能优化 */
2849
+ reportCompressedSize: false,
2850
+ // 关闭 gzip 体积计算,可小幅提升构建速度
2851
+ rollupOptions: {
2852
+ output: {
2853
+ /**
2854
+ * 优化分包策略:
2855
+ * 改进点:
2856
+ * 1. 使用正则匹配,更准确地提取 node_modules 中的包名。
2857
+ * 2. 引入 "framework" 概念,将基础框架与业务依赖分离,提升缓存命中率。
2858
+ * 3. UI 库通常较大,建议单独拆分。
2859
+ */
2860
+ manualChunks(id) {
2861
+ if (id.includes("node_modules")) {
2862
+ const normalizedId = id.replace(/\\/g, "/");
2863
+ const segments = normalizedId.split("/");
2864
+ const nmIndex = segments.lastIndexOf("node_modules");
2865
+ if (nmIndex > -1) {
2866
+ let packageName = segments[nmIndex + 1];
2867
+ if (packageName.startsWith("@")) {
2868
+ if (segments[nmIndex + 2]) {
2869
+ packageName += `/${segments[nmIndex + 2]}`;
2870
+ }
2871
+ }
2872
+ if (["vue", "react", "react-dom", "pinia", "vuex", "react-router-dom", "vue-router"].includes(packageName)) {
2873
+ return "framework";
2874
+ }
2875
+ if (["element-plus", "ant-design-vue", "arco-design", "antd", "@arco-design/web-vue"].includes(packageName)) {
2876
+ return "ui-lib";
2877
+ }
2878
+ if (["lodash-es", "lodash", "echarts", "moment", "axios", "three"].includes(packageName)) {
2879
+ return `lib-${packageName}`;
2880
+ }
2881
+ return "vendor";
2882
+ }
2861
2883
  }
2862
- return "vendor";
2863
- }
2864
- if (id.includes("src/views/")) {
2865
- const viewName = _optionalChain([id, 'access', _105 => _105.split, 'call', _106 => _106("src/views/"), 'access', _107 => _107[1], 'optionalAccess', _108 => _108.split, 'call', _109 => _109("/"), 'access', _110 => _110[0]]) || "views";
2866
- return `page-${viewName}`;
2867
- }
2868
- },
2869
- /** 入口文件命名规则:js目录/入口名.8位哈希.js */
2870
- entryFileNames: `js/[name].[contenthash:8].js`,
2871
- // 静态资源命名:图片/字体/CSS 按类型分类
2872
- assetFileNames: (assetInfo) => {
2873
- const ext = _optionalChain([assetInfo, 'access', _111 => _111.name, 'optionalAccess', _112 => _112.split, 'call', _113 => _113("."), 'access', _114 => _114.pop, 'call', _115 => _115()]) || "";
2874
- if (["png", "jpg", "jpeg", "gif", "svg", "webp"].includes(ext)) {
2875
- return `images/[name].[contenthash:8].[ext]`;
2876
- }
2877
- if (["woff", "woff2", "ttf", "eot"].includes(ext)) {
2878
- return `fonts/[name].[contenthash:8].[ext]`;
2879
- }
2880
- if (ext === "css") {
2881
- return `css/[name].[contenthash:8].[ext]`;
2884
+ if (id.includes("src/views/")) {
2885
+ const parts = id.split("src/views/");
2886
+ if (parts[1]) {
2887
+ const viewDir = parts[1].split("/")[0];
2888
+ return `page-${viewDir}`;
2889
+ }
2890
+ }
2891
+ },
2892
+ /** 入口文件命名规则:js目录/入口名.8位哈希.js */
2893
+ entryFileNames: `js/[name].[hash:8].js`,
2894
+ // 非入口 chunk 文件
2895
+ chunkFileNames: "js/[name].[hash:8].js",
2896
+ // 静态资源命名
2897
+ assetFileNames: (assetInfo) => {
2898
+ const ext = _optionalChain([assetInfo, 'access', _99 => _99.name, 'optionalAccess', _100 => _100.split, 'call', _101 => _101("."), 'access', _102 => _102.pop, 'call', _103 => _103()]) || "";
2899
+ if (["png", "jpg", "jpeg", "gif", "svg", "webp", "ico", "avif"].includes(ext)) {
2900
+ return `images/[name].[hash:8].[ext]`;
2901
+ }
2902
+ if (["woff", "woff2", "ttf", "eot", "otf"].includes(ext)) {
2903
+ return `fonts/[name].[hash:8].[ext]`;
2904
+ }
2905
+ if (["mp4", "webm", "ogg", "mp3", "wav", "flac"].includes(ext)) {
2906
+ return `media/[name].[hash:8].[ext]`;
2907
+ }
2908
+ if (ext === "css") {
2909
+ return `css/[name].[hash:8].[ext]`;
2910
+ }
2911
+ return `assets/[name].[hash:8].[ext]`;
2882
2912
  }
2883
- return `assets/[name].[contenthash:8].[ext]`;
2884
- },
2885
- /**
2886
- * 非入口 chunk 文件命名规则
2887
- * @param chunkInfo - 包含 chunk 元信息的配置对象
2888
- * @returns {string} 基于父级目录结构的文件路径
2889
- */
2890
- chunkFileNames: (chunkInfo) => {
2891
- const modulePath = _optionalChain([chunkInfo, 'access', _116 => _116.facadeModuleId, 'optionalAccess', _117 => _117.split, 'call', _118 => _118("/")]) || [];
2892
- const fileName = modulePath[modulePath.length - 3] || modulePath[modulePath.length - 2] || "[name]";
2893
- return `js/${fileName}/[name].[contenthash:8].js`;
2894
- },
2895
- // 启用代码分割优化:保留模块结构,减少冗余
2896
- preserveModules: !isProduction,
2897
- // 开发环境保留模块结构,生产环境合并
2898
- preserveModulesRoot: "src"
2899
- // 保留 src 目录结构
2913
+ }
2900
2914
  }
2901
- }
2915
+ };
2902
2916
  };
2917
+ var build_default = config;
2903
2918
 
2904
2919
  // src/vite-config/index.ts
2905
2920
  function createBaseViteConfig(options) {
2906
- return _vite.defineConfig.call(void 0, (config) => {
2907
- const env = _vite.loadEnv.call(void 0, config.mode, process.cwd(), "VITE_");
2908
- const isDev = config.mode === "development";
2921
+ return _vite.defineConfig.call(void 0, (config2) => {
2922
+ const env = _vite.loadEnv.call(void 0, config2.mode, process.cwd(), "VITE_");
2923
+ const isDev = config2.mode === "development";
2924
+ const isProd = config2.mode === "production";
2909
2925
  const { port = 5e3, plugins = [], proxy, showDevTools = false, enableOptimizeDeps = true, baseUrl } = options;
2926
+ const buildConfig = build_default(isProd);
2910
2927
  return {
2911
2928
  plugins: createVitePlugins(plugins, showDevTools, isDev),
2912
2929
  resolve: resolve_default,
2913
2930
  base: env.VITE_APP_PUBLIC_URL || "",
2914
2931
  server: server_default(port, proxy, baseUrl),
2915
- build: build_default,
2932
+ build: buildConfig,
2933
+ esbuild: isProd ? {
2934
+ drop: ["console", "debugger"],
2935
+ legalComments: "none",
2936
+ // 移除注释中的版权信息等
2937
+ pure: ["console.log"]
2938
+ // 仅标记纯函数,配合 drop 使用
2939
+ } : void 0,
2940
+ treeshake: isProd ? { preset: "recommended" } : true,
2916
2941
  optimizeDeps: {
2917
2942
  include: enableOptimizeDeps ? ["vue", "vue-router", "pinia", "axios", "element-plus", "ant-design-vue", "echarts"] : []
2918
2943
  }
@@ -56,7 +56,6 @@ import path from "path";
56
56
  var LIB_ROOT_DIR = path.resolve(__dirname, ".");
57
57
  var COMMON_ICONS_DIR = path.join(LIB_ROOT_DIR, "icons");
58
58
  function createUnoConfig(iconCollections) {
59
- console.log("createUnoConfig", COMMON_ICONS_DIR);
60
59
  return defineConfig({
61
60
  presets: [
62
61
  presetUno(),
@@ -194,7 +194,7 @@ var hmrCache = /* @__PURE__ */ new Map();
194
194
  var prevCache = /* @__PURE__ */ new Map();
195
195
  function createDescriptor(filename, source, {
196
196
  root,
197
- isProduction: isProduction2,
197
+ isProduction,
198
198
  sourceMap,
199
199
  compiler,
200
200
  template,
@@ -215,11 +215,11 @@ function createDescriptor(filename, source, {
215
215
  descriptor.id = componentIdGenerator(
216
216
  normalizedPath,
217
217
  source,
218
- isProduction2,
218
+ isProduction,
219
219
  getHash
220
220
  );
221
221
  } else {
222
- descriptor.id = getHash(normalizedPath + (isProduction2 ? source : ""));
222
+ descriptor.id = getHash(normalizedPath + (isProduction ? source : ""));
223
223
  }
224
224
  (hmr ? hmrCache : cache).set(filename, descriptor);
225
225
  return { descriptor, errors };
@@ -2005,7 +2005,7 @@ export default (sfc, props) => {
2005
2005
  }
2006
2006
  `;
2007
2007
  async function transformMain(code, filename, options, pluginContext, ssr, customElement) {
2008
- const { devServer, isProduction: isProduction2, devToolsEnabled } = options;
2008
+ const { devServer, isProduction, devToolsEnabled } = options;
2009
2009
  const prevDescriptor = getPrevDescriptor(filename);
2010
2010
  const { descriptor, errors } = createDescriptor(filename, code, options);
2011
2011
  if (fs.existsSync(filename)) {
@@ -2075,13 +2075,13 @@ async function transformMain(code, filename, options, pluginContext, ssr, custom
2075
2075
  if (hasScoped) {
2076
2076
  attachedProps.push([`__scopeId`, JSON.stringify(`data-v-${descriptor.id}`)]);
2077
2077
  }
2078
- if (devToolsEnabled || devServer && !isProduction2) {
2078
+ if (devToolsEnabled || devServer && !isProduction) {
2079
2079
  attachedProps.push([
2080
2080
  `__file`,
2081
- JSON.stringify(isProduction2 ? path.basename(filename) : filename)
2081
+ JSON.stringify(isProduction ? path.basename(filename) : filename)
2082
2082
  ]);
2083
2083
  }
2084
- if (devServer && devServer.config.server.hmr !== false && !ssr && !isProduction2) {
2084
+ if (devServer && devServer.config.server.hmr !== false && !ssr && !isProduction) {
2085
2085
  output.push(`_sfc_main.__hmrId = ${JSON.stringify(descriptor.id)}`);
2086
2086
  output.push(
2087
2087
  `typeof __VUE_HMR_RUNTIME__ !== 'undefined' && __VUE_HMR_RUNTIME__.createRecord(_sfc_main.__hmrId, _sfc_main)`
@@ -2522,7 +2522,7 @@ function vuePlugin(rawOptions = {}) {
2522
2522
  );
2523
2523
  }
2524
2524
  },
2525
- config(config) {
2525
+ config(config2) {
2526
2526
  const parseDefine = (v) => {
2527
2527
  try {
2528
2528
  return typeof v === "string" ? JSON.parse(v) : v;
@@ -2532,32 +2532,32 @@ function vuePlugin(rawOptions = {}) {
2532
2532
  };
2533
2533
  return {
2534
2534
  resolve: {
2535
- dedupe: config.build?.ssr ? [] : ["vue"]
2535
+ dedupe: config2.build?.ssr ? [] : ["vue"]
2536
2536
  },
2537
2537
  define: {
2538
- __VUE_OPTIONS_API__: options.value.features?.optionsAPI ?? parseDefine(config.define?.__VUE_OPTIONS_API__) ?? true,
2539
- __VUE_PROD_DEVTOOLS__: (options.value.features?.prodDevtools || parseDefine(config.define?.__VUE_PROD_DEVTOOLS__)) ?? false,
2538
+ __VUE_OPTIONS_API__: options.value.features?.optionsAPI ?? parseDefine(config2.define?.__VUE_OPTIONS_API__) ?? true,
2539
+ __VUE_PROD_DEVTOOLS__: (options.value.features?.prodDevtools || parseDefine(config2.define?.__VUE_PROD_DEVTOOLS__)) ?? false,
2540
2540
  __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: (options.value.features?.prodHydrationMismatchDetails || parseDefine(
2541
- config.define?.__VUE_PROD_HYDRATION_MISMATCH_DETAILS__
2541
+ config2.define?.__VUE_PROD_HYDRATION_MISMATCH_DETAILS__
2542
2542
  )) ?? false
2543
2543
  },
2544
2544
  ssr: {
2545
2545
  // @ts-ignore -- config.legacy.buildSsrCjsExternalHeuristics will be removed in Vite 5
2546
- external: config.legacy?.buildSsrCjsExternalHeuristics ? ["vue", "@vue/server-renderer"] : []
2546
+ external: config2.legacy?.buildSsrCjsExternalHeuristics ? ["vue", "@vue/server-renderer"] : []
2547
2547
  }
2548
2548
  };
2549
2549
  },
2550
- configResolved(config) {
2550
+ configResolved(config2) {
2551
2551
  options.value = {
2552
2552
  ...options.value,
2553
- root: config.root,
2554
- sourceMap: config.command === "build" ? !!config.build.sourcemap : true,
2555
- cssDevSourcemap: config.css?.devSourcemap ?? false,
2556
- isProduction: config.isProduction,
2557
- devToolsEnabled: !!(options.value.features?.prodDevtools || config.define.__VUE_PROD_DEVTOOLS__ || !config.isProduction)
2553
+ root: config2.root,
2554
+ sourceMap: config2.command === "build" ? !!config2.build.sourcemap : true,
2555
+ cssDevSourcemap: config2.css?.devSourcemap ?? false,
2556
+ isProduction: config2.isProduction,
2557
+ devToolsEnabled: !!(options.value.features?.prodDevtools || config2.define.__VUE_PROD_DEVTOOLS__ || !config2.isProduction)
2558
2558
  };
2559
- const _warn = config.logger.warn;
2560
- config.logger.warn = (...args) => {
2559
+ const _warn = config2.logger.warn;
2560
+ config2.logger.warn = (...args) => {
2561
2561
  const msg = args[0];
2562
2562
  if (msg.match(
2563
2563
  /\[lightningcss\] '(deep|slotted|global)' is not recognized as a valid pseudo-/
@@ -2566,7 +2566,7 @@ function vuePlugin(rawOptions = {}) {
2566
2566
  }
2567
2567
  _warn(...args);
2568
2568
  };
2569
- transformCachedModule = config.command === "build" && options.value.sourceMap && config.build.watch != null;
2569
+ transformCachedModule = config2.command === "build" && options.value.sourceMap && config2.build.watch != null;
2570
2570
  },
2571
2571
  shouldTransformCachedModule({ id }) {
2572
2572
  if (transformCachedModule && parseVueRequest(id).query.vue) {
@@ -2823,96 +2823,121 @@ function server_default(devPort = 5e3, proxyConfig, baseUrl = "/") {
2823
2823
 
2824
2824
  // src/vite-config/build/index.ts
2825
2825
  import path3 from "path";
2826
- var isProduction = process.env.NODE_ENV === "production";
2827
- var build_default = {
2828
- /** 构建配置:设置 chunk 体积警告阈值为 1.5MB */
2829
- minify: isProduction ? "esbuild" : false,
2830
- // 禁用代码压缩
2831
- esbuild: isProduction ? {
2832
- drop: ["console", "debugger"],
2833
- // 生产环境移除 console/debugger
2834
- pure: ["console.log", "debugger"]
2835
- // 标记纯函数,进一步压缩
2836
- } : void 0,
2837
- sourcemap: isProduction ? "hidden-source-map" : true,
2838
- // 生成源映射文件
2839
- chunkSizeWarningLimit: 1500,
2840
- // 构建性能优化:启用缓存、指定目标环境
2841
- cacheDir: path3.resolve(__dirname, "node_modules/.vite-cache"),
2842
- // 缓存构建产物
2843
- target: isProduction ? ["es2020", "chrome89", "safari14"] : "esnext",
2844
- // 生产环境适配主流浏览器
2845
- // Tree-Shaking 优化:强制开启生产环境 Tree-Shaking
2846
- treeshake: isProduction ? { moduleSideEffects: false } : true,
2847
- rollupOptions: {
2848
- output: {
2849
- /**
2850
- * 优化分包策略:
2851
- * 1. 大依赖(>100KB)单独分包
2852
- * 2. 小依赖合并到 vendor,减少 chunk 数量
2853
- * 3. 避免重复分包
2854
- */
2855
- manualChunks(id) {
2856
- if (id.includes("node_modules")) {
2857
- const moduleName = id.split("node_modules/")[1]?.split("/")[0] || "";
2858
- const largeDeps = ["lodash", "moment", "unocss", "axios", "echarts"];
2859
- if (largeDeps.includes(moduleName)) {
2860
- return `vendor-${moduleName}`;
2826
+ import { fileURLToPath } from "url";
2827
+ var __filename = fileURLToPath(import.meta.url);
2828
+ var __dirname = path3.dirname(__filename);
2829
+ var config = (isProduction) => {
2830
+ return {
2831
+ /**
2832
+ * 1. 压缩配置
2833
+ * 使用 esbuild 进行压缩,速度极快。
2834
+ * legalComments: 'none' 可以移除注释,进一步减小体积。
2835
+ */
2836
+ minify: isProduction ? "esbuild" : false,
2837
+ /** 2. Source Map 配置 */
2838
+ sourcemap: isProduction ? false : true,
2839
+ // 线上环境不生成 source map
2840
+ /** 3. 构建阈值优化 */
2841
+ chunkSizeWarningLimit: 1e3,
2842
+ // 建议调整为 1000KB,避免单个 chunk 过大影响首屏
2843
+ /** 4. 目标环境与缓存 */
2844
+ target: isProduction ? ["es2020", "chrome89", "edge88", "firefox78", "safari14"] : "esnext",
2845
+ /** 5. CSS 处理 */
2846
+ cssCodeSplit: true,
2847
+ // 启用 CSS 代码分割
2848
+ /** 6. 性能优化 */
2849
+ reportCompressedSize: false,
2850
+ // 关闭 gzip 体积计算,可小幅提升构建速度
2851
+ rollupOptions: {
2852
+ output: {
2853
+ /**
2854
+ * 优化分包策略:
2855
+ * 改进点:
2856
+ * 1. 使用正则匹配,更准确地提取 node_modules 中的包名。
2857
+ * 2. 引入 "framework" 概念,将基础框架与业务依赖分离,提升缓存命中率。
2858
+ * 3. UI 库通常较大,建议单独拆分。
2859
+ */
2860
+ manualChunks(id) {
2861
+ if (id.includes("node_modules")) {
2862
+ const normalizedId = id.replace(/\\/g, "/");
2863
+ const segments = normalizedId.split("/");
2864
+ const nmIndex = segments.lastIndexOf("node_modules");
2865
+ if (nmIndex > -1) {
2866
+ let packageName = segments[nmIndex + 1];
2867
+ if (packageName.startsWith("@")) {
2868
+ if (segments[nmIndex + 2]) {
2869
+ packageName += `/${segments[nmIndex + 2]}`;
2870
+ }
2871
+ }
2872
+ if (["vue", "react", "react-dom", "pinia", "vuex", "react-router-dom", "vue-router"].includes(packageName)) {
2873
+ return "framework";
2874
+ }
2875
+ if (["element-plus", "ant-design-vue", "arco-design", "antd", "@arco-design/web-vue"].includes(packageName)) {
2876
+ return "ui-lib";
2877
+ }
2878
+ if (["lodash-es", "lodash", "echarts", "moment", "axios", "three"].includes(packageName)) {
2879
+ return `lib-${packageName}`;
2880
+ }
2881
+ return "vendor";
2882
+ }
2861
2883
  }
2862
- return "vendor";
2863
- }
2864
- if (id.includes("src/views/")) {
2865
- const viewName = id.split("src/views/")[1]?.split("/")[0] || "views";
2866
- return `page-${viewName}`;
2867
- }
2868
- },
2869
- /** 入口文件命名规则:js目录/入口名.8位哈希.js */
2870
- entryFileNames: `js/[name].[contenthash:8].js`,
2871
- // 静态资源命名:图片/字体/CSS 按类型分类
2872
- assetFileNames: (assetInfo) => {
2873
- const ext = assetInfo.name?.split(".").pop() || "";
2874
- if (["png", "jpg", "jpeg", "gif", "svg", "webp"].includes(ext)) {
2875
- return `images/[name].[contenthash:8].[ext]`;
2876
- }
2877
- if (["woff", "woff2", "ttf", "eot"].includes(ext)) {
2878
- return `fonts/[name].[contenthash:8].[ext]`;
2879
- }
2880
- if (ext === "css") {
2881
- return `css/[name].[contenthash:8].[ext]`;
2884
+ if (id.includes("src/views/")) {
2885
+ const parts = id.split("src/views/");
2886
+ if (parts[1]) {
2887
+ const viewDir = parts[1].split("/")[0];
2888
+ return `page-${viewDir}`;
2889
+ }
2890
+ }
2891
+ },
2892
+ /** 入口文件命名规则:js目录/入口名.8位哈希.js */
2893
+ entryFileNames: `js/[name].[hash:8].js`,
2894
+ // 非入口 chunk 文件
2895
+ chunkFileNames: "js/[name].[hash:8].js",
2896
+ // 静态资源命名
2897
+ assetFileNames: (assetInfo) => {
2898
+ const ext = assetInfo.name?.split(".").pop() || "";
2899
+ if (["png", "jpg", "jpeg", "gif", "svg", "webp", "ico", "avif"].includes(ext)) {
2900
+ return `images/[name].[hash:8].[ext]`;
2901
+ }
2902
+ if (["woff", "woff2", "ttf", "eot", "otf"].includes(ext)) {
2903
+ return `fonts/[name].[hash:8].[ext]`;
2904
+ }
2905
+ if (["mp4", "webm", "ogg", "mp3", "wav", "flac"].includes(ext)) {
2906
+ return `media/[name].[hash:8].[ext]`;
2907
+ }
2908
+ if (ext === "css") {
2909
+ return `css/[name].[hash:8].[ext]`;
2910
+ }
2911
+ return `assets/[name].[hash:8].[ext]`;
2882
2912
  }
2883
- return `assets/[name].[contenthash:8].[ext]`;
2884
- },
2885
- /**
2886
- * 非入口 chunk 文件命名规则
2887
- * @param chunkInfo - 包含 chunk 元信息的配置对象
2888
- * @returns {string} 基于父级目录结构的文件路径
2889
- */
2890
- chunkFileNames: (chunkInfo) => {
2891
- const modulePath = chunkInfo.facadeModuleId?.split("/") || [];
2892
- const fileName = modulePath[modulePath.length - 3] || modulePath[modulePath.length - 2] || "[name]";
2893
- return `js/${fileName}/[name].[contenthash:8].js`;
2894
- },
2895
- // 启用代码分割优化:保留模块结构,减少冗余
2896
- preserveModules: !isProduction,
2897
- // 开发环境保留模块结构,生产环境合并
2898
- preserveModulesRoot: "src"
2899
- // 保留 src 目录结构
2913
+ }
2900
2914
  }
2901
- }
2915
+ };
2902
2916
  };
2917
+ var build_default = config;
2903
2918
 
2904
2919
  // src/vite-config/index.ts
2905
2920
  function createBaseViteConfig(options) {
2906
- return defineConfig((config) => {
2907
- const env = loadEnv(config.mode, process.cwd(), "VITE_");
2908
- const isDev = config.mode === "development";
2921
+ return defineConfig((config2) => {
2922
+ const env = loadEnv(config2.mode, process.cwd(), "VITE_");
2923
+ const isDev = config2.mode === "development";
2924
+ const isProd = config2.mode === "production";
2909
2925
  const { port = 5e3, plugins = [], proxy, showDevTools = false, enableOptimizeDeps = true, baseUrl } = options;
2926
+ const buildConfig = build_default(isProd);
2910
2927
  return {
2911
2928
  plugins: createVitePlugins(plugins, showDevTools, isDev),
2912
2929
  resolve: resolve_default,
2913
2930
  base: env.VITE_APP_PUBLIC_URL || "",
2914
2931
  server: server_default(port, proxy, baseUrl),
2915
- build: build_default,
2932
+ build: buildConfig,
2933
+ esbuild: isProd ? {
2934
+ drop: ["console", "debugger"],
2935
+ legalComments: "none",
2936
+ // 移除注释中的版权信息等
2937
+ pure: ["console.log"]
2938
+ // 仅标记纯函数,配合 drop 使用
2939
+ } : void 0,
2940
+ treeshake: isProd ? { preset: "recommended" } : true,
2916
2941
  optimizeDeps: {
2917
2942
  include: enableOptimizeDeps ? ["vue", "vue-router", "pinia", "axios", "element-plus", "ant-design-vue", "echarts"] : []
2918
2943
  }
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkZIUN3ZQAjs = require('./chunk-ZIUN3ZQA.js');
3
+ var _chunk3YUIFF3Jjs = require('./chunk-3YUIFF3J.js');
4
4
 
5
5
 
6
6
 
@@ -32,7 +32,7 @@ var _chunkZIUN3ZQAjs = require('./chunk-ZIUN3ZQA.js');
32
32
  var _chunkWGOU4SV3js = require('./chunk-WGOU4SV3.js');
33
33
 
34
34
 
35
- var _chunkMNVJK77Mjs = require('./chunk-MNVJK77M.js');
35
+ var _chunkDXEPT6A7js = require('./chunk-DXEPT6A7.js');
36
36
  require('./chunk-QGM4M3NI.js');
37
37
 
38
38
 
@@ -64,4 +64,4 @@ require('./chunk-QGM4M3NI.js');
64
64
 
65
65
 
66
66
 
67
- exports.clamp = _chunkWGOU4SV3js.clamp; exports.createBaseViteConfig = _chunkMNVJK77Mjs.createBaseViteConfig; exports.createFunctionalComponent = _chunkWGOU4SV3js.createFunctionalComponent; exports.createUnoConfig = _chunkZIUN3ZQAjs.createUnoConfig; exports.duplicateRemovalCompleteSort = _chunkWGOU4SV3js.duplicateRemovalCompleteSort; exports.encryptPwd = _chunkWGOU4SV3js.encryptPwd; exports.filterMenu = _chunkWGOU4SV3js.filterMenu; exports.formatNumber = _chunkWGOU4SV3js.formatNumber; exports.getDecimalPart = _chunkWGOU4SV3js.getDecimalPart; exports.getIntegerPart = _chunkWGOU4SV3js.getIntegerPart; exports.isInteger = _chunkWGOU4SV3js.isInteger; exports.isNumber = _chunkWGOU4SV3js.isNumber; exports.jsonp = _chunkWGOU4SV3js.jsonp; exports.listSort = _chunkWGOU4SV3js.listSort; exports.numberToChinese = _chunkWGOU4SV3js.numberToChinese; exports.padZero = _chunkWGOU4SV3js.padZero; exports.parseFormattedNumber = _chunkWGOU4SV3js.parseFormattedNumber; exports.prototypeInterceptor = _chunkWGOU4SV3js.prototypeInterceptor; exports.request = _chunkWGOU4SV3js.request; exports.roundOrTruncate = _chunkWGOU4SV3js.roundOrTruncate; exports.setupPermission = _chunkWGOU4SV3js.setupPermission; exports.store = _chunkWGOU4SV3js.store; exports.timeFix = _chunkWGOU4SV3js.timeFix; exports.updateDocumentTitle = _chunkWGOU4SV3js.updateDocumentTitle; exports.useCommonStore = _chunkWGOU4SV3js.useCommonStore; exports.useDbStore = _chunkWGOU4SV3js.useDbStore; exports.useLoginHook = _chunkWGOU4SV3js.useLoginHook; exports.useMenuStore = _chunkWGOU4SV3js.useMenuStore; exports.welcome = _chunkWGOU4SV3js.welcome;
67
+ exports.clamp = _chunkWGOU4SV3js.clamp; exports.createBaseViteConfig = _chunkDXEPT6A7js.createBaseViteConfig; exports.createFunctionalComponent = _chunkWGOU4SV3js.createFunctionalComponent; exports.createUnoConfig = _chunk3YUIFF3Jjs.createUnoConfig; exports.duplicateRemovalCompleteSort = _chunkWGOU4SV3js.duplicateRemovalCompleteSort; exports.encryptPwd = _chunkWGOU4SV3js.encryptPwd; exports.filterMenu = _chunkWGOU4SV3js.filterMenu; exports.formatNumber = _chunkWGOU4SV3js.formatNumber; exports.getDecimalPart = _chunkWGOU4SV3js.getDecimalPart; exports.getIntegerPart = _chunkWGOU4SV3js.getIntegerPart; exports.isInteger = _chunkWGOU4SV3js.isInteger; exports.isNumber = _chunkWGOU4SV3js.isNumber; exports.jsonp = _chunkWGOU4SV3js.jsonp; exports.listSort = _chunkWGOU4SV3js.listSort; exports.numberToChinese = _chunkWGOU4SV3js.numberToChinese; exports.padZero = _chunkWGOU4SV3js.padZero; exports.parseFormattedNumber = _chunkWGOU4SV3js.parseFormattedNumber; exports.prototypeInterceptor = _chunkWGOU4SV3js.prototypeInterceptor; exports.request = _chunkWGOU4SV3js.request; exports.roundOrTruncate = _chunkWGOU4SV3js.roundOrTruncate; exports.setupPermission = _chunkWGOU4SV3js.setupPermission; exports.store = _chunkWGOU4SV3js.store; exports.timeFix = _chunkWGOU4SV3js.timeFix; exports.updateDocumentTitle = _chunkWGOU4SV3js.updateDocumentTitle; exports.useCommonStore = _chunkWGOU4SV3js.useCommonStore; exports.useDbStore = _chunkWGOU4SV3js.useDbStore; exports.useLoginHook = _chunkWGOU4SV3js.useLoginHook; exports.useMenuStore = _chunkWGOU4SV3js.useMenuStore; exports.welcome = _chunkWGOU4SV3js.welcome;
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createUnoConfig
3
- } from "./chunk-DDLZE36T.mjs";
3
+ } from "./chunk-H523LVQA.mjs";
4
4
  import {
5
5
  clamp,
6
6
  createFunctionalComponent,
@@ -32,7 +32,7 @@ import {
32
32
  } from "./chunk-PTS5WW6S.mjs";
33
33
  import {
34
34
  createBaseViteConfig
35
- } from "./chunk-BRRQ7FAH.mjs";
35
+ } from "./chunk-OD4FOBV2.mjs";
36
36
  import "./chunk-6DZX6EAA.mjs";
37
37
  export {
38
38
  clamp,
@@ -1,9 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunkZIUN3ZQAjs = require('../chunk-ZIUN3ZQA.js');
4
+ var _chunk3YUIFF3Jjs = require('../chunk-3YUIFF3J.js');
5
5
  require('../chunk-QGM4M3NI.js');
6
6
 
7
7
 
8
8
 
9
- exports.createUnoConfig = _chunkZIUN3ZQAjs.createUnoConfig; exports.default = _chunkZIUN3ZQAjs.uno_config_default;
9
+ exports.createUnoConfig = _chunk3YUIFF3Jjs.createUnoConfig; exports.default = _chunk3YUIFF3Jjs.uno_config_default;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createUnoConfig,
3
3
  uno_config_default
4
- } from "../chunk-DDLZE36T.mjs";
4
+ } from "../chunk-H523LVQA.mjs";
5
5
  import "../chunk-6DZX6EAA.mjs";
6
6
  export {
7
7
  createUnoConfig,
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkMNVJK77Mjs = require('../chunk-MNVJK77M.js');
3
+ var _chunkDXEPT6A7js = require('../chunk-DXEPT6A7.js');
4
4
  require('../chunk-QGM4M3NI.js');
5
5
 
6
6
 
7
- exports.createBaseViteConfig = _chunkMNVJK77Mjs.createBaseViteConfig;
7
+ exports.createBaseViteConfig = _chunkDXEPT6A7js.createBaseViteConfig;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createBaseViteConfig
3
- } from "../chunk-BRRQ7FAH.mjs";
3
+ } from "../chunk-OD4FOBV2.mjs";
4
4
  import "../chunk-6DZX6EAA.mjs";
5
5
  export {
6
6
  createBaseViteConfig
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.2.1",
6
+ "version": "0.2.3",
7
7
  "description": "共享工具库和类型定义",
8
8
  "author": "ebuilds",
9
9
  "license": "MIT",