jinbi-utils 1.0.19 → 1.0.21

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 (81) hide show
  1. package/.babelrc +19 -0
  2. package/.cz-config.js +55 -0
  3. package/.dockerignore +3 -0
  4. package/.editorconfig +12 -0
  5. package/.eslintignore +8 -0
  6. package/.eslintrc.js +54 -0
  7. package/.versionrc.json +9 -0
  8. package/CHUNK_OPTIMIZER_USAGE.md +132 -0
  9. package/Dockerfile +3 -0
  10. package/QUICK_RELEASE.md +85 -0
  11. package/RELEASE_GUIDE.md +243 -0
  12. package/api-extractor.json +15 -0
  13. package/commitlint.config.js +3 -0
  14. package/jest.config.js +15 -0
  15. package/package.json +8 -35
  16. package/rollup.config.chunk-optimizer.js +32 -0
  17. package/rollup.config.js +73 -0
  18. package/src/array/index.ts +85 -0
  19. package/src/build/chunk-optimizer/ARCHITECTURE.md +347 -0
  20. package/src/build/chunk-optimizer/QUICK_START.md +370 -0
  21. package/src/build/chunk-optimizer/README.md +240 -0
  22. package/src/build/chunk-optimizer/core/chunk-generator.ts +166 -0
  23. package/src/build/chunk-optimizer/core/classifier.ts +148 -0
  24. package/src/build/chunk-optimizer/core/dependency-reader.ts +138 -0
  25. package/src/build/chunk-optimizer/examples/basic-usage.ts +234 -0
  26. package/src/build/chunk-optimizer/index.ts +166 -0
  27. package/src/build/chunk-optimizer/rules/common-rules.ts +131 -0
  28. package/src/build/chunk-optimizer/rules/framework-rules.ts +93 -0
  29. package/src/build/chunk-optimizer/rules/index.ts +27 -0
  30. package/src/build/chunk-optimizer/test.ts +94 -0
  31. package/src/build/chunk-optimizer/types.ts +128 -0
  32. package/src/color/index.ts +58 -0
  33. package/src/common/index.ts +353 -0
  34. package/src/constant/common.constant.ts +13 -0
  35. package/src/date/index.ts +143 -0
  36. package/src/dom/index.ts +198 -0
  37. package/src/file/index.ts +319 -0
  38. package/src/http/apiBuilder/README.md +648 -0
  39. package/src/http/apiBuilder/api-builder.ts +502 -0
  40. package/src/http/apiBuilder/example.ts +243 -0
  41. package/src/http/apiBuilder/index.ts +1 -0
  42. package/src/http/apiBuilder//345/277/253/351/200/237/345/217/202/350/200/203.md +199 -0
  43. package/src/http/http.ts +79 -0
  44. package/src/http/httpEnums.ts +61 -0
  45. package/src/iam/index.ts +46 -0
  46. package/src/index.ts +20 -0
  47. package/src/middleware/requestLogger.middware.ts +371 -0
  48. package/src/middleware/requestLoggerUnified.ts +371 -0
  49. package/src/number/index.ts +362 -0
  50. package/src/object/index.ts +54 -0
  51. package/src/print/index.ts +102 -0
  52. package/src/string/index.ts +189 -0
  53. package/src/utils/curl.ts +108 -0
  54. package/src/validate/index.ts +100 -0
  55. package/src/websocket/emitter.ts +39 -0
  56. package/src/websocket/index.ts +6 -0
  57. package/src/websocket/manager.ts +151 -0
  58. package/src/websocket/pinia-store.ts +91 -0
  59. package/src/websocket/service.ts +34 -0
  60. package/src/websocket/types.ts +45 -0
  61. package/test/common/index.test.ts +19 -0
  62. package/test/date/index.test.ts +107 -0
  63. package/test/file/index.test.ts +104 -0
  64. package/test/number/index.test.ts +108 -0
  65. package/test/object/index.test.ts +20 -0
  66. package/test/string/index.test.ts +82 -0
  67. package/tsconfig.json +39 -0
  68. package/typedoc.json +12 -0
  69. package/types/file/index.d.ts +7 -0
  70. package/types/index.d.ts +1 -0
  71. package/types/websocket/emitter.d.ts +16 -0
  72. package/types/websocket/index.d.ts +6 -0
  73. package/types/websocket/manager.d.ts +36 -0
  74. package/types/websocket/pinia-store.d.ts +25 -0
  75. package/types/websocket/service.d.ts +13 -0
  76. package/types/websocket/types.d.ts +34 -0
  77. package/dist/chunk-optimizer.cjs +0 -703
  78. package/dist/index.esm.js +0 -2791
  79. package/dist/index.esm.min.js +0 -15
  80. package/dist/index.umd.js +0 -2899
  81. package/dist/index.umd.min.js +0 -16
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Chunk 生成器 - 生成 manualChunks 函数
3
+ */
4
+ import type {
5
+ ManualChunksFunction,
6
+ DependencyInfo,
7
+ SourceCodeStrategy,
8
+ } from '../types';
9
+
10
+ /**
11
+ * Chunk 生成器
12
+ */
13
+ export class ChunkGenerator {
14
+ private dependencyMap: Map<string, string>;
15
+ private sourceCodeStrategy: SourceCodeStrategy;
16
+ private debug: boolean;
17
+
18
+ constructor(
19
+ dependencies: DependencyInfo[],
20
+ sourceCodeStrategy: SourceCodeStrategy = {},
21
+ debug: boolean = false
22
+ ) {
23
+ // 构建依赖名称到分类的映射
24
+ this.dependencyMap = new Map();
25
+ dependencies.forEach(dep => {
26
+ if (dep.category) {
27
+ this.dependencyMap.set(dep.name, dep.category);
28
+ }
29
+ });
30
+
31
+ this.sourceCodeStrategy = {
32
+ views: true,
33
+ components: true,
34
+ utils: true,
35
+ store: true,
36
+ ...sourceCodeStrategy,
37
+ };
38
+
39
+ this.debug = debug;
40
+ }
41
+
42
+ /**
43
+ * 从模块 ID 中提取包名
44
+ */
45
+ private extractPackageName(id: string): string | null {
46
+ const match = id.match(/node_modules\/(@[^/]+\/[^/]+|[^/]+)/);
47
+ return match ? match[1] : null;
48
+ }
49
+
50
+ /**
51
+ * 处理 node_modules 依赖
52
+ */
53
+ private handleNodeModules(id: string): string | undefined {
54
+ const packageName = this.extractPackageName(id);
55
+
56
+ if (!packageName) {
57
+ return undefined;
58
+ }
59
+
60
+ // 查找依赖分类
61
+ const category = this.dependencyMap.get(packageName);
62
+
63
+ if (this.debug && category) {
64
+ console.log(`[Chunk] ${packageName} -> ${category}`);
65
+ }
66
+
67
+ return category;
68
+ }
69
+
70
+ /**
71
+ * 处理业务代码
72
+ */
73
+ private handleSourceCode(id: string): string | undefined {
74
+ // 处理 views 目录
75
+ if (this.sourceCodeStrategy.views && id.includes('/src/views/')) {
76
+ const match = id.match(/\/src\/views\/([^/]+)\//);
77
+ if (match) {
78
+ return `chunk-${match[1]}`;
79
+ }
80
+ return 'chunk-views';
81
+ }
82
+
83
+ // 处理 components 目录
84
+ if (this.sourceCodeStrategy.components && id.includes('/src/components/')) {
85
+ return 'chunk-components';
86
+ }
87
+
88
+ // 处理 utils 和 config 目录
89
+ if (this.sourceCodeStrategy.utils) {
90
+ if (id.includes('/src/utils/') || id.includes('/src/config/')) {
91
+ return 'chunk-common';
92
+ }
93
+ }
94
+
95
+ // 处理 store 目录
96
+ if (this.sourceCodeStrategy.store && id.includes('/src/store/')) {
97
+ return 'chunk-store';
98
+ }
99
+
100
+ // 处理自定义规则
101
+ if (this.sourceCodeStrategy.custom) {
102
+ for (const rule of this.sourceCodeStrategy.custom) {
103
+ if (rule.pattern.test(id)) {
104
+ return rule.chunkName;
105
+ }
106
+ }
107
+ }
108
+
109
+ return undefined;
110
+ }
111
+
112
+ /**
113
+ * 生成 manualChunks 函数
114
+ */
115
+ generate(): ManualChunksFunction {
116
+ return (id: string) => {
117
+ // 处理 node_modules 依赖
118
+ if (id.includes('node_modules')) {
119
+ return this.handleNodeModules(id);
120
+ }
121
+
122
+ // 处理业务代码
123
+ return this.handleSourceCode(id);
124
+ };
125
+ }
126
+
127
+ /**
128
+ * 获取依赖统计信息
129
+ */
130
+ getStats(): {
131
+ totalDependencies: number;
132
+ categorizedDependencies: number;
133
+ categories: string[];
134
+ } {
135
+ const categories = new Set<string>();
136
+ this.dependencyMap.forEach(category => {
137
+ categories.add(category);
138
+ });
139
+
140
+ return {
141
+ totalDependencies: this.dependencyMap.size,
142
+ categorizedDependencies: this.dependencyMap.size,
143
+ categories: Array.from(categories).sort(),
144
+ };
145
+ }
146
+
147
+ /**
148
+ * 打印统计信息
149
+ */
150
+ printStats(): void {
151
+ const stats = this.getStats();
152
+
153
+ console.log('\n🎯 Chunk Optimizer - Statistics\n');
154
+ console.log(`Total dependencies: ${stats.totalDependencies}`);
155
+ console.log(`Categorized: ${stats.categorizedDependencies}`);
156
+ console.log(`\nChunk categories (${stats.categories.length}):`);
157
+ stats.categories.forEach(category => {
158
+ const count = Array.from(this.dependencyMap.values()).filter(
159
+ c => c === category
160
+ ).length;
161
+ console.log(` - ${category}: ${count} packages`);
162
+ });
163
+ console.log('');
164
+ }
165
+ }
166
+
@@ -0,0 +1,148 @@
1
+ /**
2
+ * 分类引擎 - 根据规则对依赖进行分类
3
+ */
4
+ import type { Rule, DependencyInfo, DependencyCategory } from '../types';
5
+ import { getAllRules, sortRulesByPriority } from '../rules';
6
+
7
+ /**
8
+ * 依赖分类器
9
+ */
10
+ export class DependencyClassifier {
11
+ private rules: Rule[];
12
+ private customRules: Record<string, DependencyCategory>;
13
+ private exclude: string[];
14
+
15
+ constructor(
16
+ framework: string = 'auto',
17
+ customRules: Record<string, DependencyCategory> = {},
18
+ exclude: string[] = []
19
+ ) {
20
+ // 获取并排序规则(按优先级)
21
+ this.rules = sortRulesByPriority(getAllRules(framework as any));
22
+ this.customRules = customRules;
23
+ this.exclude = exclude;
24
+ }
25
+
26
+ /**
27
+ * 检查是否应该排除某个包
28
+ */
29
+ private shouldExclude(packageName: string): boolean {
30
+ return this.exclude.some(pattern => {
31
+ if (pattern.includes('*')) {
32
+ // 支持通配符匹配
33
+ const regex = new RegExp('^' + pattern.replace(/\*/g, '.*') + '$');
34
+ return regex.test(packageName);
35
+ }
36
+ return packageName === pattern;
37
+ });
38
+ }
39
+
40
+ /**
41
+ * 匹配规则
42
+ */
43
+ private matchRule(packageName: string, rule: Rule): boolean {
44
+ if (typeof rule.match === 'string') {
45
+ return packageName === rule.match;
46
+ } else {
47
+ return rule.match.test(packageName);
48
+ }
49
+ }
50
+
51
+ /**
52
+ * 对单个依赖进行分类
53
+ */
54
+ classifyDependency(dep: DependencyInfo): DependencyCategory | null {
55
+ // 检查是否应该排除
56
+ if (this.shouldExclude(dep.name)) {
57
+ return null;
58
+ }
59
+
60
+ // 优先使用自定义规则
61
+ if (this.customRules[dep.name]) {
62
+ return this.customRules[dep.name];
63
+ }
64
+
65
+ // 检查自定义规则中的通配符
66
+ for (const [pattern, category] of Object.entries(this.customRules)) {
67
+ if (pattern.includes('*')) {
68
+ const regex = new RegExp('^' + pattern.replace(/\*/g, '.*') + '$');
69
+ if (regex.test(dep.name)) {
70
+ return category;
71
+ }
72
+ }
73
+ }
74
+
75
+ // 使用预定义规则
76
+ for (const rule of this.rules) {
77
+ if (this.matchRule(dep.name, rule)) {
78
+ return rule.category;
79
+ }
80
+ }
81
+
82
+ // 默认分类
83
+ return 'vendor-libs';
84
+ }
85
+
86
+ /**
87
+ * 对所有依赖进行分类
88
+ */
89
+ classifyAll(dependencies: DependencyInfo[]): DependencyInfo[] {
90
+ return dependencies.map(dep => ({
91
+ ...dep,
92
+ category: this.classifyDependency(dep) || undefined,
93
+ }));
94
+ }
95
+
96
+ /**
97
+ * 获取分类统计
98
+ */
99
+ getCategoryStats(dependencies: DependencyInfo[]): Record<DependencyCategory, number> {
100
+ const stats: Record<string, number> = {};
101
+
102
+ dependencies.forEach(dep => {
103
+ if (dep.category) {
104
+ stats[dep.category] = (stats[dep.category] || 0) + 1;
105
+ }
106
+ });
107
+
108
+ return stats;
109
+ }
110
+
111
+ /**
112
+ * 打印分类信息(调试用)
113
+ */
114
+ printClassification(dependencies: DependencyInfo[]): void {
115
+ console.log('\n📦 Chunk Optimizer - Dependency Classification\n');
116
+
117
+ const categorized = this.classifyAll(dependencies);
118
+ const stats = this.getCategoryStats(categorized);
119
+
120
+ // 按分类分组
121
+ const grouped: Record<string, string[]> = {};
122
+ categorized.forEach(dep => {
123
+ if (dep.category) {
124
+ if (!grouped[dep.category]) {
125
+ grouped[dep.category] = [];
126
+ }
127
+ grouped[dep.category].push(dep.name);
128
+ }
129
+ });
130
+
131
+ // 打印每个分类
132
+ Object.entries(grouped)
133
+ .sort(([a], [b]) => a.localeCompare(b))
134
+ .forEach(([category, packages]) => {
135
+ console.log(`\n${category} (${packages.length}):`);
136
+ packages.forEach(pkg => {
137
+ console.log(` - ${pkg}`);
138
+ });
139
+ });
140
+
141
+ console.log('\n📊 Summary:');
142
+ console.log(` Total dependencies: ${dependencies.length}`);
143
+ console.log(` Categorized: ${categorized.filter(d => d.category).length}`);
144
+ console.log(` Categories: ${Object.keys(stats).length}`);
145
+ console.log('');
146
+ }
147
+ }
148
+
@@ -0,0 +1,138 @@
1
+ /**
2
+ * 依赖读取器 - 读取和解析 package.json
3
+ */
4
+ import { readFileSync, existsSync } from 'fs';
5
+ import { resolve } from 'path';
6
+ import type { DependencyInfo, Framework } from '../types';
7
+
8
+ /**
9
+ * Package.json 结构
10
+ */
11
+ interface PackageJson {
12
+ dependencies?: Record<string, string>;
13
+ devDependencies?: Record<string, string>;
14
+ }
15
+
16
+ /**
17
+ * 依赖读取器类
18
+ */
19
+ export class DependencyReader {
20
+ private packageJsonPath: string;
21
+ private packageJson: PackageJson | null = null;
22
+
23
+ constructor(packageJsonPath?: string) {
24
+ // 默认使用项目根目录的 package.json
25
+ this.packageJsonPath = packageJsonPath || resolve(process.cwd(), 'package.json');
26
+ }
27
+
28
+ /**
29
+ * 读取 package.json
30
+ */
31
+ private readPackageJson(): PackageJson {
32
+ if (this.packageJson) {
33
+ return this.packageJson;
34
+ }
35
+
36
+ if (!existsSync(this.packageJsonPath)) {
37
+ throw new Error(`package.json not found at: ${this.packageJsonPath}`);
38
+ }
39
+
40
+ try {
41
+ const content = readFileSync(this.packageJsonPath, 'utf-8');
42
+ this.packageJson = JSON.parse(content);
43
+ return this.packageJson!;
44
+ } catch (error) {
45
+ throw new Error(`Failed to parse package.json: ${error}`);
46
+ }
47
+ }
48
+
49
+ /**
50
+ * 获取所有依赖信息
51
+ */
52
+ getDependencies(): DependencyInfo[] {
53
+ const pkg = this.readPackageJson();
54
+ const dependencies: DependencyInfo[] = [];
55
+
56
+ // 读取生产依赖
57
+ if (pkg.dependencies) {
58
+ Object.entries(pkg.dependencies).forEach(([name, version]) => {
59
+ dependencies.push({
60
+ name,
61
+ version,
62
+ isDev: false,
63
+ });
64
+ });
65
+ }
66
+
67
+ // 读取开发依赖
68
+ if (pkg.devDependencies) {
69
+ Object.entries(pkg.devDependencies).forEach(([name, version]) => {
70
+ dependencies.push({
71
+ name,
72
+ version,
73
+ isDev: true,
74
+ });
75
+ });
76
+ }
77
+
78
+ return dependencies;
79
+ }
80
+
81
+ /**
82
+ * 检测项目使用的框架
83
+ */
84
+ detectFramework(): Framework {
85
+ const pkg = this.readPackageJson();
86
+ const allDeps = {
87
+ ...pkg.dependencies,
88
+ ...pkg.devDependencies,
89
+ };
90
+
91
+ // 检测 Vue
92
+ if (allDeps['vue']) {
93
+ return 'vue';
94
+ }
95
+
96
+ // 检测 React
97
+ if (allDeps['react']) {
98
+ return 'react';
99
+ }
100
+
101
+ // 检测 Angular
102
+ if (allDeps['@angular/core']) {
103
+ return 'angular';
104
+ }
105
+
106
+ // 检测 Svelte
107
+ if (allDeps['svelte']) {
108
+ return 'svelte';
109
+ }
110
+
111
+ // 默认返回 auto
112
+ return 'auto';
113
+ }
114
+
115
+ /**
116
+ * 检查是否存在某个依赖
117
+ */
118
+ hasDependency(name: string): boolean {
119
+ const pkg = this.readPackageJson();
120
+ return !!(
121
+ pkg.dependencies?.[name] ||
122
+ pkg.devDependencies?.[name]
123
+ );
124
+ }
125
+
126
+ /**
127
+ * 获取依赖版本
128
+ */
129
+ getDependencyVersion(name: string): string | null {
130
+ const pkg = this.readPackageJson();
131
+ return (
132
+ pkg.dependencies?.[name] ||
133
+ pkg.devDependencies?.[name] ||
134
+ null
135
+ );
136
+ }
137
+ }
138
+
@@ -0,0 +1,234 @@
1
+ /**
2
+ * Chunk Optimizer 使用示例
3
+ */
4
+
5
+ import { createChunkOptimizer } from '../index';
6
+
7
+ // ============================================================
8
+ // 示例 1: 零配置使用(推荐)
9
+ // ============================================================
10
+ export function example1() {
11
+ const optimizer = createChunkOptimizer();
12
+
13
+ return {
14
+ build: {
15
+ rollupOptions: {
16
+ output: {
17
+ manualChunks: optimizer.generate()
18
+ }
19
+ }
20
+ }
21
+ };
22
+ }
23
+
24
+ // ============================================================
25
+ // 示例 2: 启用调试模式
26
+ // ============================================================
27
+ export function example2() {
28
+ const optimizer = createChunkOptimizer({
29
+ debug: true, // 会在构建时打印详细的分包信息
30
+ });
31
+
32
+ // 手动打印分析报告
33
+ optimizer.printReport();
34
+
35
+ return {
36
+ build: {
37
+ rollupOptions: {
38
+ output: {
39
+ manualChunks: optimizer.generate()
40
+ }
41
+ }
42
+ }
43
+ };
44
+ }
45
+
46
+ // ============================================================
47
+ // 示例 3: 自定义规则
48
+ // ============================================================
49
+ export function example3() {
50
+ const optimizer = createChunkOptimizer({
51
+ framework: 'vue',
52
+ customRules: {
53
+ // 将公司内部库单独分包
54
+ '@company/ui': 'vendor-company-ui',
55
+ '@company/utils': 'vendor-company-utils',
56
+
57
+ // 将某个大型库单独分包
58
+ 'echarts': 'vendor-echarts',
59
+
60
+ // 使用通配符匹配
61
+ '@company/*': 'vendor-company',
62
+ },
63
+ });
64
+
65
+ return {
66
+ build: {
67
+ rollupOptions: {
68
+ output: {
69
+ manualChunks: optimizer.generate()
70
+ }
71
+ }
72
+ }
73
+ };
74
+ }
75
+
76
+ // ============================================================
77
+ // 示例 4: 排除某些包
78
+ // ============================================================
79
+ export function example4() {
80
+ const optimizer = createChunkOptimizer({
81
+ exclude: [
82
+ '@types/*', // 排除所有类型定义
83
+ 'vite', // 排除 vite
84
+ 'rollup', // 排除 rollup
85
+ 'esbuild', // 排除 esbuild
86
+ ],
87
+ });
88
+
89
+ return {
90
+ build: {
91
+ rollupOptions: {
92
+ output: {
93
+ manualChunks: optimizer.generate()
94
+ }
95
+ }
96
+ }
97
+ };
98
+ }
99
+
100
+ // ============================================================
101
+ // 示例 5: 自定义业务代码分包
102
+ // ============================================================
103
+ export function example5() {
104
+ const optimizer = createChunkOptimizer({
105
+ sourceCodeStrategy: {
106
+ views: true, // 按 views 模块分包
107
+ components: true, // 公共组件单独分包
108
+ utils: true, // 工具函数分包
109
+ store: true, // store 分包
110
+ custom: [
111
+ // 自定义业务代码分包规则
112
+ {
113
+ pattern: /\/src\/features\/([^/]+)\//,
114
+ chunkName: 'feature-$1'
115
+ },
116
+ {
117
+ pattern: /\/src\/modules\/([^/]+)\//,
118
+ chunkName: 'module-$1'
119
+ }
120
+ ]
121
+ }
122
+ });
123
+
124
+ return {
125
+ build: {
126
+ rollupOptions: {
127
+ output: {
128
+ manualChunks: optimizer.generate()
129
+ }
130
+ }
131
+ }
132
+ };
133
+ }
134
+
135
+ // ============================================================
136
+ // 示例 6: React 项目使用
137
+ // ============================================================
138
+ export function example6React() {
139
+ const optimizer = createChunkOptimizer({
140
+ framework: 'react', // 指定框架为 React
141
+ customRules: {
142
+ // React 项目特定的规则
143
+ 'react-query': 'vendor-query',
144
+ '@tanstack/react-query': 'vendor-query',
145
+ },
146
+ });
147
+
148
+ return {
149
+ build: {
150
+ rollupOptions: {
151
+ output: {
152
+ manualChunks: optimizer.generate()
153
+ }
154
+ }
155
+ }
156
+ };
157
+ }
158
+
159
+ // ============================================================
160
+ // 示例 7: 完整配置示例
161
+ // ============================================================
162
+ export function example7Complete() {
163
+ const optimizer = createChunkOptimizer({
164
+ // 框架类型
165
+ framework: 'vue',
166
+
167
+ // 启用调试
168
+ debug: process.env.NODE_ENV === 'development',
169
+
170
+ // 自定义规则
171
+ customRules: {
172
+ '@company/*': 'vendor-company',
173
+ 'echarts': 'vendor-echarts',
174
+ },
175
+
176
+ // 排除包
177
+ exclude: ['@types/*', 'vite'],
178
+
179
+ // 业务代码分包
180
+ sourceCodeStrategy: {
181
+ views: true,
182
+ components: true,
183
+ utils: true,
184
+ store: true,
185
+ custom: [
186
+ {
187
+ pattern: /\/src\/features\/([^/]+)\//,
188
+ chunkName: 'feature-$1'
189
+ }
190
+ ]
191
+ }
192
+ });
193
+
194
+ return {
195
+ build: {
196
+ rollupOptions: {
197
+ output: {
198
+ chunkFileNames: 'static/js/[name]-[hash].js',
199
+ entryFileNames: 'static/js/[name]-[hash].js',
200
+ assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
201
+ manualChunks: optimizer.generate()
202
+ }
203
+ }
204
+ }
205
+ };
206
+ }
207
+
208
+ // ============================================================
209
+ // 示例 8: 获取分析结果
210
+ // ============================================================
211
+ export function example8Analysis() {
212
+ const optimizer = createChunkOptimizer();
213
+
214
+ // 获取分析结果
215
+ const result = optimizer.analyze();
216
+
217
+ console.log('检测到的框架:', result.detectedFramework);
218
+ console.log('依赖总数:', result.dependencies.length);
219
+ console.log('分类统计:', result.categoryStats);
220
+
221
+ // 打印详细报告
222
+ optimizer.printReport();
223
+
224
+ return {
225
+ build: {
226
+ rollupOptions: {
227
+ output: {
228
+ manualChunks: optimizer.generate()
229
+ }
230
+ }
231
+ }
232
+ };
233
+ }
234
+