code-abyss 1.6.16 → 1.7.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.
Files changed (92) hide show
  1. package/package.json +2 -2
  2. package/skills/SKILL.md +24 -16
  3. package/skills/domains/ai/SKILL.md +2 -2
  4. package/skills/domains/ai/prompt-and-eval.md +279 -0
  5. package/skills/domains/architecture/SKILL.md +2 -3
  6. package/skills/domains/architecture/security-arch.md +87 -0
  7. package/skills/domains/data-engineering/SKILL.md +188 -26
  8. package/skills/domains/development/SKILL.md +1 -4
  9. package/skills/domains/devops/SKILL.md +3 -5
  10. package/skills/domains/devops/performance.md +63 -0
  11. package/skills/domains/devops/testing.md +97 -0
  12. package/skills/domains/frontend-design/SKILL.md +12 -3
  13. package/skills/domains/frontend-design/claymorphism/SKILL.md +117 -0
  14. package/skills/domains/frontend-design/claymorphism/references/tokens.css +52 -0
  15. package/skills/domains/frontend-design/engineering.md +287 -0
  16. package/skills/domains/frontend-design/glassmorphism/SKILL.md +138 -0
  17. package/skills/domains/frontend-design/glassmorphism/references/tokens.css +32 -0
  18. package/skills/domains/frontend-design/liquid-glass/SKILL.md +135 -0
  19. package/skills/domains/frontend-design/liquid-glass/references/tokens.css +81 -0
  20. package/skills/domains/frontend-design/neubrutalism/SKILL.md +141 -0
  21. package/skills/domains/frontend-design/neubrutalism/references/tokens.css +44 -0
  22. package/skills/domains/infrastructure/SKILL.md +174 -34
  23. package/skills/domains/mobile/SKILL.md +211 -21
  24. package/skills/domains/orchestration/SKILL.md +1 -0
  25. package/skills/domains/security/SKILL.md +4 -6
  26. package/skills/domains/security/blue-team.md +57 -0
  27. package/skills/domains/security/red-team.md +54 -0
  28. package/skills/domains/security/threat-intel.md +50 -0
  29. package/skills/orchestration/multi-agent/SKILL.md +195 -46
  30. package/skills/run_skill.js +134 -0
  31. package/skills/tools/gen-docs/SKILL.md +6 -4
  32. package/skills/tools/gen-docs/scripts/doc_generator.js +349 -0
  33. package/skills/tools/verify-change/SKILL.md +8 -6
  34. package/skills/tools/verify-change/scripts/change_analyzer.js +270 -0
  35. package/skills/tools/verify-module/SKILL.md +6 -4
  36. package/skills/tools/verify-module/scripts/module_scanner.js +145 -0
  37. package/skills/tools/verify-quality/SKILL.md +5 -3
  38. package/skills/tools/verify-quality/scripts/quality_checker.js +276 -0
  39. package/skills/tools/verify-security/SKILL.md +7 -5
  40. package/skills/tools/verify-security/scripts/security_scanner.js +133 -0
  41. package/skills/__pycache__/run_skill.cpython-312.pyc +0 -0
  42. package/skills/domains/COVERAGE_PLAN.md +0 -232
  43. package/skills/domains/ai/model-evaluation.md +0 -790
  44. package/skills/domains/ai/prompt-engineering.md +0 -703
  45. package/skills/domains/architecture/compliance.md +0 -299
  46. package/skills/domains/architecture/data-security.md +0 -184
  47. package/skills/domains/data-engineering/data-pipeline.md +0 -762
  48. package/skills/domains/data-engineering/data-quality.md +0 -894
  49. package/skills/domains/data-engineering/stream-processing.md +0 -791
  50. package/skills/domains/development/dart.md +0 -963
  51. package/skills/domains/development/kotlin.md +0 -834
  52. package/skills/domains/development/php.md +0 -659
  53. package/skills/domains/development/swift.md +0 -755
  54. package/skills/domains/devops/e2e-testing.md +0 -914
  55. package/skills/domains/devops/performance-testing.md +0 -734
  56. package/skills/domains/devops/testing-strategy.md +0 -667
  57. package/skills/domains/frontend-design/build-tools.md +0 -743
  58. package/skills/domains/frontend-design/performance.md +0 -734
  59. package/skills/domains/frontend-design/testing.md +0 -699
  60. package/skills/domains/infrastructure/gitops.md +0 -735
  61. package/skills/domains/infrastructure/iac.md +0 -855
  62. package/skills/domains/infrastructure/kubernetes.md +0 -1018
  63. package/skills/domains/mobile/android-dev.md +0 -979
  64. package/skills/domains/mobile/cross-platform.md +0 -795
  65. package/skills/domains/mobile/ios-dev.md +0 -931
  66. package/skills/domains/security/secrets-management.md +0 -834
  67. package/skills/domains/security/supply-chain.md +0 -931
  68. package/skills/domains/security/threat-modeling.md +0 -828
  69. package/skills/run_skill.py +0 -153
  70. package/skills/tests/README.md +0 -225
  71. package/skills/tests/SUMMARY.md +0 -362
  72. package/skills/tests/__init__.py +0 -3
  73. package/skills/tests/__pycache__/test_change_analyzer.cpython-312.pyc +0 -0
  74. package/skills/tests/__pycache__/test_doc_generator.cpython-312.pyc +0 -0
  75. package/skills/tests/__pycache__/test_module_scanner.cpython-312.pyc +0 -0
  76. package/skills/tests/__pycache__/test_quality_checker.cpython-312.pyc +0 -0
  77. package/skills/tests/__pycache__/test_security_scanner.cpython-312.pyc +0 -0
  78. package/skills/tests/test_change_analyzer.py +0 -558
  79. package/skills/tests/test_doc_generator.py +0 -538
  80. package/skills/tests/test_module_scanner.py +0 -376
  81. package/skills/tests/test_quality_checker.py +0 -516
  82. package/skills/tests/test_security_scanner.py +0 -426
  83. package/skills/tools/gen-docs/scripts/__pycache__/doc_generator.cpython-312.pyc +0 -0
  84. package/skills/tools/gen-docs/scripts/doc_generator.py +0 -520
  85. package/skills/tools/verify-change/scripts/__pycache__/change_analyzer.cpython-312.pyc +0 -0
  86. package/skills/tools/verify-change/scripts/change_analyzer.py +0 -529
  87. package/skills/tools/verify-module/scripts/__pycache__/module_scanner.cpython-312.pyc +0 -0
  88. package/skills/tools/verify-module/scripts/module_scanner.py +0 -321
  89. package/skills/tools/verify-quality/scripts/__pycache__/quality_checker.cpython-312.pyc +0 -0
  90. package/skills/tools/verify-quality/scripts/quality_checker.py +0 -481
  91. package/skills/tools/verify-security/scripts/__pycache__/security_scanner.cpython-312.pyc +0 -0
  92. package/skills/tools/verify-security/scripts/security_scanner.py +0 -374
@@ -1,743 +0,0 @@
1
- ---
2
- name: build-tools
3
- description: 前端构建工具。Vite、Webpack、Turbopack、esbuild、构建优化、插件生态。当用户提到构建工具、Vite、Webpack、Turbopack、打包优化、构建配置时使用。
4
- ---
5
-
6
- # 🎨 🔧 构建工具 · Build Tools
7
-
8
- ## 构建工具对比
9
-
10
- | 工具 | 开发速度 | 生产构建 | 生态 | 学习曲线 | 适用场景 |
11
- |------|----------|----------|------|----------|----------|
12
- | Vite | 极快 | 快 | 成熟 | 低 | 现代项目、快速开发 |
13
- | Webpack | 慢 | 中 | 最丰富 | 陡峭 | 复杂配置、企业项目 |
14
- | Turbopack | 极快 | 快 | 新兴 | 低 | Next.js 项目 |
15
- | esbuild | 极快 | 极快 | 基础 | 低 | 简单项目、库打包 |
16
- | Rollup | 中 | 快 | 成熟 | 中 | 库打包、Tree Shaking |
17
- | Parcel | 快 | 快 | 中等 | 极低 | 零配置项目 |
18
-
19
- ## 选择决策树
20
-
21
- ```
22
- 选择构建工具?
23
-
24
- ├─ 新项目
25
- │ ├─ React/Vue → Vite
26
- │ ├─ Next.js → Turbopack (内置)
27
- │ └─ 零配置 → Parcel
28
-
29
- ├─ 库开发
30
- │ ├─ 需要 Tree Shaking → Rollup
31
- │ └─ 极致性能 → esbuild
32
-
33
- └─ 老项目
34
- ├─ 复杂配置 → 保持 Webpack
35
- └─ 可迁移 → 迁移到 Vite
36
- ```
37
-
38
- ## Vite (推荐)
39
-
40
- ### 基础配置
41
-
42
- ```typescript
43
- // vite.config.ts
44
- import { defineConfig } from 'vite'
45
- import react from '@vitejs/plugin-react'
46
- import path from 'path'
47
-
48
- export default defineConfig({
49
- plugins: [react()],
50
- resolve: {
51
- alias: {
52
- '@': path.resolve(__dirname, './src'),
53
- '@components': path.resolve(__dirname, './src/components'),
54
- '@utils': path.resolve(__dirname, './src/utils'),
55
- },
56
- },
57
- server: {
58
- port: 3000,
59
- open: true,
60
- proxy: {
61
- '/api': {
62
- target: 'http://localhost:8080',
63
- changeOrigin: true,
64
- rewrite: (path) => path.replace(/^\/api/, ''),
65
- },
66
- },
67
- },
68
- build: {
69
- outDir: 'dist',
70
- sourcemap: true,
71
- rollupOptions: {
72
- output: {
73
- manualChunks: {
74
- 'react-vendor': ['react', 'react-dom'],
75
- 'router': ['react-router-dom'],
76
- },
77
- },
78
- },
79
- },
80
- })
81
- ```
82
-
83
- ### 环境变量
84
-
85
- ```typescript
86
- // .env
87
- VITE_API_URL=https://api.example.com
88
- VITE_APP_TITLE=My App
89
-
90
- // .env.development
91
- VITE_API_URL=http://localhost:8080
92
-
93
- // .env.production
94
- VITE_API_URL=https://prod-api.example.com
95
-
96
- // 使用环境变量
97
- const apiUrl = import.meta.env.VITE_API_URL
98
- const isDev = import.meta.env.DEV
99
- const isProd = import.meta.env.PROD
100
- ```
101
-
102
- ### 自定义插件
103
-
104
- ```typescript
105
- // vite-plugin-custom.ts
106
- import type { Plugin } from 'vite'
107
-
108
- export function customPlugin(): Plugin {
109
- return {
110
- name: 'vite-plugin-custom',
111
-
112
- // 开发服务器启动时
113
- configureServer(server) {
114
- server.middlewares.use((req, res, next) => {
115
- console.log('Request:', req.url)
116
- next()
117
- })
118
- },
119
-
120
- // 转换代码
121
- transform(code, id) {
122
- if (id.endsWith('.custom')) {
123
- return {
124
- code: transformCustomFile(code),
125
- map: null,
126
- }
127
- }
128
- },
129
-
130
- // 构建开始
131
- buildStart() {
132
- console.log('Build started')
133
- },
134
-
135
- // 构建结束
136
- buildEnd() {
137
- console.log('Build finished')
138
- },
139
- }
140
- }
141
-
142
- // 使用插件
143
- export default defineConfig({
144
- plugins: [react(), customPlugin()],
145
- })
146
- ```
147
-
148
- ### 优化配置
149
-
150
- ```typescript
151
- // vite.config.ts
152
- export default defineConfig({
153
- build: {
154
- // 代码分割
155
- rollupOptions: {
156
- output: {
157
- manualChunks(id) {
158
- if (id.includes('node_modules')) {
159
- if (id.includes('react')) {
160
- return 'react-vendor'
161
- }
162
- if (id.includes('@mui')) {
163
- return 'mui-vendor'
164
- }
165
- return 'vendor'
166
- }
167
- },
168
- },
169
- },
170
-
171
- // 压缩配置
172
- minify: 'terser',
173
- terserOptions: {
174
- compress: {
175
- drop_console: true,
176
- drop_debugger: true,
177
- },
178
- },
179
-
180
- // Chunk 大小警告
181
- chunkSizeWarningLimit: 1000,
182
-
183
- // CSS 代码分割
184
- cssCodeSplit: true,
185
- },
186
-
187
- // 依赖预构建
188
- optimizeDeps: {
189
- include: ['react', 'react-dom', 'react-router-dom'],
190
- exclude: ['@vite/client'],
191
- },
192
- })
193
- ```
194
-
195
- ## Webpack
196
-
197
- ### 基础配置
198
-
199
- ```javascript
200
- // webpack.config.js
201
- const path = require('path')
202
- const HtmlWebpackPlugin = require('html-webpack-plugin')
203
- const MiniCssExtractPlugin = require('mini-css-extract-plugin')
204
- const TerserPlugin = require('terser-webpack-plugin')
205
-
206
- module.exports = {
207
- entry: './src/index.tsx',
208
- output: {
209
- path: path.resolve(__dirname, 'dist'),
210
- filename: '[name].[contenthash].js',
211
- clean: true,
212
- },
213
-
214
- resolve: {
215
- extensions: ['.ts', '.tsx', '.js', '.jsx'],
216
- alias: {
217
- '@': path.resolve(__dirname, 'src'),
218
- },
219
- },
220
-
221
- module: {
222
- rules: [
223
- {
224
- test: /\.(ts|tsx)$/,
225
- use: 'ts-loader',
226
- exclude: /node_modules/,
227
- },
228
- {
229
- test: /\.css$/,
230
- use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader'],
231
- },
232
- {
233
- test: /\.(png|jpg|gif|svg)$/,
234
- type: 'asset/resource',
235
- },
236
- ],
237
- },
238
-
239
- plugins: [
240
- new HtmlWebpackPlugin({
241
- template: './public/index.html',
242
- }),
243
- new MiniCssExtractPlugin({
244
- filename: '[name].[contenthash].css',
245
- }),
246
- ],
247
-
248
- optimization: {
249
- minimizer: [new TerserPlugin()],
250
- splitChunks: {
251
- chunks: 'all',
252
- cacheGroups: {
253
- vendor: {
254
- test: /[\\/]node_modules[\\/]/,
255
- name: 'vendors',
256
- priority: 10,
257
- },
258
- },
259
- },
260
- },
261
- }
262
- ```
263
-
264
- ### 开发服务器
265
-
266
- ```javascript
267
- // webpack.dev.js
268
- const { merge } = require('webpack-merge')
269
- const common = require('./webpack.config.js')
270
-
271
- module.exports = merge(common, {
272
- mode: 'development',
273
- devtool: 'inline-source-map',
274
-
275
- devServer: {
276
- static: './dist',
277
- port: 3000,
278
- hot: true,
279
- open: true,
280
- historyApiFallback: true,
281
- proxy: {
282
- '/api': {
283
- target: 'http://localhost:8080',
284
- changeOrigin: true,
285
- },
286
- },
287
- },
288
- })
289
- ```
290
-
291
- ### 生产优化
292
-
293
- ```javascript
294
- // webpack.prod.js
295
- const { merge } = require('webpack-merge')
296
- const common = require('./webpack.config.js')
297
- const CssMinimizerPlugin = require('css-minimizer-webpack-plugin')
298
- const CompressionPlugin = require('compression-webpack-plugin')
299
- const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
300
-
301
- module.exports = merge(common, {
302
- mode: 'production',
303
- devtool: 'source-map',
304
-
305
- optimization: {
306
- minimize: true,
307
- minimizer: [
308
- new TerserPlugin({
309
- terserOptions: {
310
- compress: {
311
- drop_console: true,
312
- },
313
- },
314
- }),
315
- new CssMinimizerPlugin(),
316
- ],
317
-
318
- splitChunks: {
319
- chunks: 'all',
320
- maxInitialRequests: 10,
321
- cacheGroups: {
322
- react: {
323
- test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/,
324
- name: 'react',
325
- priority: 20,
326
- },
327
- vendor: {
328
- test: /[\\/]node_modules[\\/]/,
329
- name: 'vendors',
330
- priority: 10,
331
- },
332
- },
333
- },
334
-
335
- runtimeChunk: 'single',
336
- },
337
-
338
- plugins: [
339
- new CompressionPlugin({
340
- algorithm: 'gzip',
341
- test: /\.(js|css|html|svg)$/,
342
- threshold: 10240,
343
- minRatio: 0.8,
344
- }),
345
- new BundleAnalyzerPlugin({
346
- analyzerMode: 'static',
347
- openAnalyzer: false,
348
- }),
349
- ],
350
- })
351
- ```
352
-
353
- ### 自定义 Loader
354
-
355
- ```javascript
356
- // custom-loader.js
357
- module.exports = function(source) {
358
- // 转换源代码
359
- const transformed = source.replace(/console\.log/g, '// console.log')
360
-
361
- // 返回转换后的代码
362
- return transformed
363
- }
364
-
365
- // webpack.config.js
366
- module.exports = {
367
- module: {
368
- rules: [
369
- {
370
- test: /\.js$/,
371
- use: [
372
- {
373
- loader: path.resolve(__dirname, 'custom-loader.js'),
374
- },
375
- ],
376
- },
377
- ],
378
- },
379
- }
380
- ```
381
-
382
- ### 自定义 Plugin
383
-
384
- ```javascript
385
- // custom-plugin.js
386
- class CustomPlugin {
387
- apply(compiler) {
388
- compiler.hooks.emit.tapAsync('CustomPlugin', (compilation, callback) => {
389
- // 在生成资源前执行
390
- console.log('Assets:', Object.keys(compilation.assets))
391
-
392
- // 添加自定义文件
393
- compilation.assets['custom.txt'] = {
394
- source: () => 'Custom content',
395
- size: () => 14,
396
- }
397
-
398
- callback()
399
- })
400
-
401
- compiler.hooks.done.tap('CustomPlugin', (stats) => {
402
- // 构建完成后执行
403
- console.log('Build completed!')
404
- })
405
- }
406
- }
407
-
408
- module.exports = CustomPlugin
409
-
410
- // 使用插件
411
- plugins: [new CustomPlugin()]
412
- ```
413
-
414
- ## Turbopack (Next.js)
415
-
416
- ### Next.js 配置
417
-
418
- ```javascript
419
- // next.config.js
420
- module.exports = {
421
- // 启用 Turbopack (Next.js 13+)
422
- experimental: {
423
- turbo: {
424
- rules: {
425
- '*.svg': {
426
- loaders: ['@svgr/webpack'],
427
- as: '*.js',
428
- },
429
- },
430
- resolveAlias: {
431
- '@': './src',
432
- },
433
- },
434
- },
435
-
436
- // 其他配置
437
- reactStrictMode: true,
438
- swcMinify: true,
439
-
440
- webpack: (config, { isServer }) => {
441
- // 自定义 Webpack 配置(Turbopack 不支持时回退)
442
- if (!isServer) {
443
- config.resolve.fallback = {
444
- fs: false,
445
- net: false,
446
- tls: false,
447
- }
448
- }
449
- return config
450
- },
451
- }
452
- ```
453
-
454
- ### 使用 Turbopack
455
-
456
- ```bash
457
- # 开发模式使用 Turbopack
458
- next dev --turbo
459
-
460
- # package.json
461
- {
462
- "scripts": {
463
- "dev": "next dev --turbo",
464
- "build": "next build",
465
- "start": "next start"
466
- }
467
- }
468
- ```
469
-
470
- ## esbuild
471
-
472
- ### 基础配置
473
-
474
- ```javascript
475
- // build.js
476
- const esbuild = require('esbuild')
477
-
478
- esbuild.build({
479
- entryPoints: ['src/index.tsx'],
480
- bundle: true,
481
- outfile: 'dist/bundle.js',
482
- minify: true,
483
- sourcemap: true,
484
- target: ['es2020'],
485
- loader: {
486
- '.ts': 'ts',
487
- '.tsx': 'tsx',
488
- '.png': 'file',
489
- },
490
- define: {
491
- 'process.env.NODE_ENV': '"production"',
492
- },
493
- }).catch(() => process.exit(1))
494
- ```
495
-
496
- ### 开发服务器
497
-
498
- ```javascript
499
- // serve.js
500
- const esbuild = require('esbuild')
501
-
502
- esbuild.serve(
503
- {
504
- servedir: 'public',
505
- port: 3000,
506
- },
507
- {
508
- entryPoints: ['src/index.tsx'],
509
- bundle: true,
510
- outfile: 'public/bundle.js',
511
- loader: { '.ts': 'ts', '.tsx': 'tsx' },
512
- }
513
- ).then(server => {
514
- console.log(`Server running at http://localhost:${server.port}`)
515
- })
516
- ```
517
-
518
- ### 插件系统
519
-
520
- ```javascript
521
- // esbuild-plugin-custom.js
522
- const customPlugin = {
523
- name: 'custom',
524
- setup(build) {
525
- // 解析路径
526
- build.onResolve({ filter: /^custom:/ }, args => ({
527
- path: args.path,
528
- namespace: 'custom',
529
- }))
530
-
531
- // 加载内容
532
- build.onLoad({ filter: /.*/, namespace: 'custom' }, args => ({
533
- contents: 'export default "custom content"',
534
- loader: 'js',
535
- }))
536
- },
537
- }
538
-
539
- // 使用插件
540
- esbuild.build({
541
- entryPoints: ['src/index.js'],
542
- bundle: true,
543
- plugins: [customPlugin],
544
- outfile: 'dist/bundle.js',
545
- })
546
- ```
547
-
548
- ## Rollup (库打包)
549
-
550
- ### 基础配置
551
-
552
- ```javascript
553
- // rollup.config.js
554
- import resolve from '@rollup/plugin-node-resolve'
555
- import commonjs from '@rollup/plugin-commonjs'
556
- import typescript from '@rollup/plugin-typescript'
557
- import { terser } from 'rollup-plugin-terser'
558
- import peerDepsExternal from 'rollup-plugin-peer-deps-external'
559
-
560
- export default {
561
- input: 'src/index.ts',
562
- output: [
563
- {
564
- file: 'dist/index.js',
565
- format: 'cjs',
566
- sourcemap: true,
567
- },
568
- {
569
- file: 'dist/index.esm.js',
570
- format: 'esm',
571
- sourcemap: true,
572
- },
573
- {
574
- file: 'dist/index.umd.js',
575
- format: 'umd',
576
- name: 'MyLibrary',
577
- sourcemap: true,
578
- globals: {
579
- react: 'React',
580
- 'react-dom': 'ReactDOM',
581
- },
582
- },
583
- ],
584
- plugins: [
585
- peerDepsExternal(),
586
- resolve(),
587
- commonjs(),
588
- typescript({ tsconfig: './tsconfig.json' }),
589
- terser(),
590
- ],
591
- external: ['react', 'react-dom'],
592
- }
593
- ```
594
-
595
- ## 性能优化对比
596
-
597
- | 优化项 | Vite | Webpack | Turbopack | esbuild |
598
- |--------|------|---------|-----------|---------|
599
- | 冷启动 | < 1s | 10-30s | < 1s | < 1s |
600
- | HMR | < 100ms | 1-3s | < 100ms | N/A |
601
- | 生产构建 | 10-30s | 30-60s | 10-20s | 5-10s |
602
- | Tree Shaking | ✅ | ✅ | ✅ | ✅ |
603
- | 代码分割 | ✅ | ✅ | ✅ | ✅ |
604
-
605
- ## 迁移指南
606
-
607
- ### Webpack → Vite
608
-
609
- ```typescript
610
- // 1. 安装依赖
611
- npm install -D vite @vitejs/plugin-react
612
-
613
- // 2. 创建 vite.config.ts
614
- import { defineConfig } from 'vite'
615
- import react from '@vitejs/plugin-react'
616
-
617
- export default defineConfig({
618
- plugins: [react()],
619
- resolve: {
620
- alias: {
621
- '@': '/src', // Webpack alias 迁移
622
- },
623
- },
624
- })
625
-
626
- // 3. 更新 index.html
627
- // 移动到项目根目录,添加:
628
- <script type="module" src="/src/main.tsx"></script>
629
-
630
- // 4. 更新环境变量
631
- // REACT_APP_* → VITE_*
632
-
633
- // 5. 更新 import
634
- // require() → import
635
- // import.meta.env 替代 process.env
636
- ```
637
-
638
- ## 最佳实践
639
-
640
- ### 代码分割策略
641
-
642
- ```typescript
643
- // 路由级别分割
644
- const routes = [
645
- {
646
- path: '/dashboard',
647
- component: lazy(() => import('./pages/Dashboard')),
648
- },
649
- {
650
- path: '/profile',
651
- component: lazy(() => import('./pages/Profile')),
652
- },
653
- ]
654
-
655
- // 第三方库分割
656
- // vite.config.ts
657
- export default defineConfig({
658
- build: {
659
- rollupOptions: {
660
- output: {
661
- manualChunks: {
662
- 'react-vendor': ['react', 'react-dom', 'react-router-dom'],
663
- 'ui-vendor': ['@mui/material', '@emotion/react'],
664
- 'chart-vendor': ['recharts', 'd3'],
665
- },
666
- },
667
- },
668
- },
669
- })
670
- ```
671
-
672
- ### 缓存策略
673
-
674
- ```typescript
675
- // 文件名哈希
676
- export default defineConfig({
677
- build: {
678
- rollupOptions: {
679
- output: {
680
- entryFileNames: 'assets/[name].[hash].js',
681
- chunkFileNames: 'assets/[name].[hash].js',
682
- assetFileNames: 'assets/[name].[hash].[ext]',
683
- },
684
- },
685
- },
686
- })
687
-
688
- // HTTP 缓存头
689
- // nginx.conf
690
- location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
691
- expires 1y;
692
- add_header Cache-Control "public, immutable";
693
- }
694
- ```
695
-
696
- ### 环境配置
697
-
698
- ```typescript
699
- // 多环境配置
700
- // vite.config.ts
701
- export default defineConfig(({ mode }) => {
702
- const env = loadEnv(mode, process.cwd())
703
-
704
- return {
705
- define: {
706
- __APP_VERSION__: JSON.stringify(process.env.npm_package_version),
707
- __API_URL__: JSON.stringify(env.VITE_API_URL),
708
- },
709
- build: {
710
- sourcemap: mode === 'development',
711
- minify: mode === 'production',
712
- },
713
- }
714
- })
715
- ```
716
-
717
- ## 最佳实践清单
718
-
719
- - ✅ 使用 Vite 开发新项目
720
- - ✅ 配置合理的代码分割策略
721
- - ✅ 启用 Tree Shaking 和压缩
722
- - ✅ 使用文件名哈希实现长期缓存
723
- - ✅ 配置 source map 便于调试
724
- - ✅ 使用环境变量管理配置
725
- - ✅ 定期分析 bundle 大小
726
- - ✅ 预构建常用依赖
727
- - ✅ 配置合理的 chunk 大小
728
- - ✅ 在 CI/CD 中缓存依赖
729
-
730
- ## 工具清单
731
-
732
- | 工具 | 用途 |
733
- |------|------|
734
- | Vite | 现代前端构建工具 |
735
- | Webpack | 功能最全的打包工具 |
736
- | Turbopack | Next.js 高性能构建 |
737
- | esbuild | 极速打包工具 |
738
- | Rollup | 库打包工具 |
739
- | webpack-bundle-analyzer | Bundle 分析 |
740
- | vite-plugin-inspect | Vite 插件调试 |
741
- | speed-measure-webpack-plugin | Webpack 性能分析 |
742
-
743
- ---