@meng-xi/vite-plugin 0.1.6 → 0.1.8

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 (66) hide show
  1. package/README-en.md +42 -16
  2. package/README.md +55 -29
  3. package/dist/common/concurrency/index.cjs +1 -0
  4. package/dist/common/concurrency/index.d.cts +26 -0
  5. package/dist/common/concurrency/index.d.mts +26 -0
  6. package/dist/common/concurrency/index.d.ts +26 -0
  7. package/dist/common/concurrency/index.mjs +1 -0
  8. package/dist/common/format/index.cjs +1 -1
  9. package/dist/common/format/index.d.cts +19 -1
  10. package/dist/common/format/index.d.mts +19 -1
  11. package/dist/common/format/index.d.ts +19 -1
  12. package/dist/common/format/index.mjs +1 -1
  13. package/dist/common/fs/index.cjs +1 -1
  14. package/dist/common/fs/index.d.cts +19 -1
  15. package/dist/common/fs/index.d.mts +19 -1
  16. package/dist/common/fs/index.d.ts +19 -1
  17. package/dist/common/fs/index.mjs +1 -1
  18. package/dist/common/index.cjs +1 -1
  19. package/dist/common/index.d.cts +4 -2
  20. package/dist/common/index.d.mts +4 -2
  21. package/dist/common/index.d.ts +4 -2
  22. package/dist/common/index.mjs +1 -1
  23. package/dist/common/path/index.cjs +1 -0
  24. package/dist/common/path/index.d.cts +103 -0
  25. package/dist/common/path/index.d.mts +103 -0
  26. package/dist/common/path/index.d.ts +103 -0
  27. package/dist/common/path/index.mjs +1 -0
  28. package/dist/index.cjs +1 -1
  29. package/dist/index.d.cts +6 -2
  30. package/dist/index.d.mts +6 -2
  31. package/dist/index.d.ts +6 -2
  32. package/dist/index.mjs +1 -1
  33. package/dist/plugins/assetManifest/index.cjs +1 -0
  34. package/dist/plugins/assetManifest/index.d.cts +162 -0
  35. package/dist/plugins/assetManifest/index.d.mts +162 -0
  36. package/dist/plugins/assetManifest/index.d.ts +162 -0
  37. package/dist/plugins/assetManifest/index.mjs +1 -0
  38. package/dist/plugins/autoImport/index.cjs +13 -13
  39. package/dist/plugins/autoImport/index.mjs +8 -8
  40. package/dist/plugins/bundleAnalyzer/index.cjs +1 -1
  41. package/dist/plugins/bundleAnalyzer/index.mjs +2 -2
  42. package/dist/plugins/compressAssets/index.cjs +1 -1
  43. package/dist/plugins/compressAssets/index.mjs +1 -1
  44. package/dist/plugins/copyFile/index.cjs +1 -1
  45. package/dist/plugins/copyFile/index.mjs +1 -1
  46. package/dist/plugins/envGuard/index.cjs +1 -1
  47. package/dist/plugins/envGuard/index.mjs +1 -1
  48. package/dist/plugins/faviconManager/index.cjs +1 -1
  49. package/dist/plugins/faviconManager/index.mjs +1 -1
  50. package/dist/plugins/generateRouter/index.cjs +3 -3
  51. package/dist/plugins/generateRouter/index.mjs +1 -1
  52. package/dist/plugins/generateVersion/index.cjs +1 -1
  53. package/dist/plugins/generateVersion/index.mjs +1 -1
  54. package/dist/plugins/htmlInject/index.cjs +7 -7
  55. package/dist/plugins/htmlInject/index.mjs +2 -2
  56. package/dist/plugins/imageOptimizer/index.cjs +5 -0
  57. package/dist/plugins/imageOptimizer/index.d.cts +242 -0
  58. package/dist/plugins/imageOptimizer/index.d.mts +242 -0
  59. package/dist/plugins/imageOptimizer/index.d.ts +242 -0
  60. package/dist/plugins/imageOptimizer/index.mjs +5 -0
  61. package/dist/plugins/index.cjs +1 -1
  62. package/dist/plugins/index.d.cts +2 -0
  63. package/dist/plugins/index.d.mts +2 -0
  64. package/dist/plugins/index.d.ts +2 -0
  65. package/dist/plugins/index.mjs +1 -1
  66. package/package.json +25 -1
@@ -1,6 +1,8 @@
1
- export { DateFormatOptions, formatDate, formatFileSize, getDateFormatParams, parseTemplate } from './format/index.cjs';
2
- export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport } from './fs/index.cjs';
1
+ export { runWithConcurrency } from './concurrency/index.cjs';
2
+ export { DateFormatOptions, calcRatio, formatDate, formatFileSize, getDateFormatParams, parseTemplate } from './format/index.cjs';
3
+ export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, resolveReportPath, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport } from './fs/index.cjs';
3
4
  export { SanitizeRuleOptions, escapeHtmlAttr, injectBeforeTag, injectHeadAndBody, sanitizeContent } from './html/index.cjs';
5
+ export { isExtensionIncluded, isPathExcluded, isPreCompressed, normalizePath } from './path/index.cjs';
4
6
  export { makeCallback } from './script/index.cjs';
5
7
  export { ANSI } from './ui/index.cjs';
6
8
  export { V as Validator } from '../shared/vite-plugin.DRRlWY8P.cjs';
@@ -1,6 +1,8 @@
1
- export { DateFormatOptions, formatDate, formatFileSize, getDateFormatParams, parseTemplate } from './format/index.mjs';
2
- export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport } from './fs/index.mjs';
1
+ export { runWithConcurrency } from './concurrency/index.mjs';
2
+ export { DateFormatOptions, calcRatio, formatDate, formatFileSize, getDateFormatParams, parseTemplate } from './format/index.mjs';
3
+ export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, resolveReportPath, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport } from './fs/index.mjs';
3
4
  export { SanitizeRuleOptions, escapeHtmlAttr, injectBeforeTag, injectHeadAndBody, sanitizeContent } from './html/index.mjs';
5
+ export { isExtensionIncluded, isPathExcluded, isPreCompressed, normalizePath } from './path/index.mjs';
4
6
  export { makeCallback } from './script/index.mjs';
5
7
  export { ANSI } from './ui/index.mjs';
6
8
  export { V as Validator } from '../shared/vite-plugin.DRRlWY8P.mjs';
@@ -1,6 +1,8 @@
1
- export { DateFormatOptions, formatDate, formatFileSize, getDateFormatParams, parseTemplate } from './format/index.js';
2
- export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport } from './fs/index.js';
1
+ export { runWithConcurrency } from './concurrency/index.js';
2
+ export { DateFormatOptions, calcRatio, formatDate, formatFileSize, getDateFormatParams, parseTemplate } from './format/index.js';
3
+ export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, resolveReportPath, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport } from './fs/index.js';
3
4
  export { SanitizeRuleOptions, escapeHtmlAttr, injectBeforeTag, injectHeadAndBody, sanitizeContent } from './html/index.js';
5
+ export { isExtensionIncluded, isPathExcluded, isPreCompressed, normalizePath } from './path/index.js';
4
6
  export { makeCallback } from './script/index.js';
5
7
  export { ANSI } from './ui/index.js';
6
8
  export { V as Validator } from '../shared/vite-plugin.DRRlWY8P.js';
@@ -1 +1 @@
1
- export{formatDate,formatFileSize,getDateFormatParams,parseTemplate}from"./format/index.mjs";export{checkSourceExists,copySourceToTarget,scanDirectory,shouldUpdateFileContent,writeFileContent,writeFileSyncSafely,writeJsonReport}from"./fs/index.mjs";export{injectBeforeTag,injectHeadAndBody}from"./html/index.mjs";export{makeCallback}from"./script/index.mjs";export{ANSI}from"./ui/index.mjs";export{V as Validator}from"../shared/vite-plugin.DcExl6jd.mjs";export{validateCallbackFields,validateGlobalName,validateNoScriptInTemplate}from"./validation/index.mjs";export{e as escapeHtmlAttr,s as sanitizeContent}from"../shared/vite-plugin.CuXEJAWX.mjs";import"fs";import"path";
1
+ export{runWithConcurrency}from"./concurrency/index.mjs";export{calcRatio,formatDate,formatFileSize,getDateFormatParams,parseTemplate}from"./format/index.mjs";export{checkSourceExists,copySourceToTarget,resolveReportPath,scanDirectory,shouldUpdateFileContent,writeFileContent,writeFileSyncSafely,writeJsonReport}from"./fs/index.mjs";export{injectBeforeTag,injectHeadAndBody}from"./html/index.mjs";export{isExtensionIncluded,isPathExcluded,isPreCompressed,normalizePath}from"./path/index.mjs";export{makeCallback}from"./script/index.mjs";export{ANSI}from"./ui/index.mjs";export{V as Validator}from"../shared/vite-plugin.DcExl6jd.mjs";export{validateCallbackFields,validateGlobalName,validateNoScriptInTemplate}from"./validation/index.mjs";export{e as escapeHtmlAttr,s as sanitizeContent}from"../shared/vite-plugin.CuXEJAWX.mjs";import"fs";import"path";
@@ -0,0 +1 @@
1
+ "use strict";function normalizePath(e){return e.replace(/\\/g,"/")}function isExtensionIncluded(e,s){const{includeExtensions:r=[],excludeExtensions:t=[]}=s;return!(t.length>0&&t.includes(e)||r.length>0&&!r.includes(e))}function isPathExcluded(e,s,r={}){if(s.length===0)return!1;const t=normalizePath(e),{matchMode:i="simple"}=r;for(const o of s){const n=normalizePath(o);if(i==="segment"){if(t.startsWith(n+"/")||t===n||t.includes("/"+n+"/")||t.endsWith("/"+n))return!0}else if(t.startsWith(n)||t.includes(n))return!0}return!1}function isPreCompressed(e){return e===".gz"||e===".br"}exports.isExtensionIncluded=isExtensionIncluded,exports.isPathExcluded=isPathExcluded,exports.isPreCompressed=isPreCompressed,exports.normalizePath=normalizePath;
@@ -0,0 +1,103 @@
1
+ /**
2
+ * 路径处理工具函数
3
+ *
4
+ * @description 提供跨平台路径规范化、扩展名过滤、路径排除匹配等通用功能,
5
+ * 供多个插件复用,避免重复实现。
6
+ */
7
+ /**
8
+ * 将路径中的反斜杠转换为正斜杠,确保跨平台一致性
9
+ *
10
+ * @param {string} filePath - 待规范化的文件路径
11
+ * @returns {string} 使用正斜杠的路径字符串
12
+ *
13
+ * @description Windows 系统下路径使用反斜杠 `\`,而 Unix 系统使用正斜杠 `/`。
14
+ * 统一转换为正斜杠可避免跨平台路径比较失败。
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * normalizePath('assets\\index-abc123.js')
19
+ * // 'assets/index-abc123.js'
20
+ *
21
+ * normalizePath('assets/index.js')
22
+ * // 'assets/index.js'
23
+ * ```
24
+ */
25
+ declare function normalizePath(filePath: string): string;
26
+ /**
27
+ * 检查文件扩展名是否通过包含/排除过滤条件
28
+ *
29
+ * @param {string} ext - 文件扩展名(小写,含点号,如 `.js`)
30
+ * @param {object} options - 过滤选项
31
+ * @param {string[]} [options.includeExtensions] - 包含的扩展名列表(为空则包含所有)
32
+ * @param {string[]} [options.excludeExtensions] - 排除的扩展名列表
33
+ * @returns {boolean} 扩展名是否通过过滤(`true` 表示应包含该文件)
34
+ *
35
+ * @description 按以下优先级判断:
36
+ * 1. 如果 `excludeExtensions` 非空且扩展名在其中,返回 `false`
37
+ * 2. 如果 `includeExtensions` 非空且扩展名不在其中,返回 `false`
38
+ * 3. 其余情况返回 `true`
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * isExtensionIncluded('.js', { includeExtensions: ['.js', '.css'], excludeExtensions: [] })
43
+ * // true
44
+ *
45
+ * isExtensionIncluded('.map', { includeExtensions: [], excludeExtensions: ['.map'] })
46
+ * // false
47
+ *
48
+ * isExtensionIncluded('.js', { includeExtensions: [], excludeExtensions: [] })
49
+ * // true(两个列表均为空,包含所有)
50
+ * ```
51
+ */
52
+ declare function isExtensionIncluded(ext: string, options: {
53
+ includeExtensions?: string[];
54
+ excludeExtensions?: string[];
55
+ }): boolean;
56
+ /**
57
+ * 检查文件路径是否匹配排除路径列表
58
+ *
59
+ * @param {string} relativePath - 文件的相对路径(应先使用 {@link normalizePath} 规范化)
60
+ * @param {string[]} excludePaths - 排除路径列表
61
+ * @param {object} [options] - 匹配选项
62
+ * @param {'simple' | 'segment'} [options.matchMode='simple'] - 匹配模式:
63
+ * - `'simple'`:简单的 startsWith / includes 匹配
64
+ * - `'segment'`:基于路径段边界的精确匹配,避免子字符串误匹配
65
+ * @returns {boolean} 路径是否应被排除(`true` 表示应排除)
66
+ *
67
+ * @description 根据匹配模式检查路径是否命中排除列表:
68
+ * - **simple 模式**:路径以排除项开头或包含排除项即命中
69
+ * - **segment 模式**:基于路径段边界匹配,确保 `excludePaths: ['test']` 不会误排除 `testdata/`
70
+ *
71
+ * 路径比较前会自动调用 {@link normalizePath} 统一分隔符。
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * isPathExcluded('assets/test/file.js', ['test'])
76
+ * // true(simple 模式,默认)
77
+ *
78
+ * isPathExcluded('testdata/file.js', ['test'], { matchMode: 'segment' })
79
+ * // false(segment 模式,'testdata' 不等于路径段 'test')
80
+ *
81
+ * isPathExcluded('assets/test/file.js', ['test'], { matchMode: 'segment' })
82
+ * // true('test' 匹配路径段)
83
+ * ```
84
+ */
85
+ declare function isPathExcluded(relativePath: string, excludePaths: string[], options?: {
86
+ matchMode?: 'simple' | 'segment';
87
+ }): boolean;
88
+ /**
89
+ * 检查扩展名是否为已压缩格式
90
+ *
91
+ * @param {string} ext - 文件扩展名(小写,含点号)
92
+ * @returns {boolean} 是否为已压缩格式(`.gz` 或 `.br`)
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * isPreCompressed('.gz') // true
97
+ * isPreCompressed('.br') // true
98
+ * isPreCompressed('.js') // false
99
+ * ```
100
+ */
101
+ declare function isPreCompressed(ext: string): boolean;
102
+
103
+ export { isExtensionIncluded, isPathExcluded, isPreCompressed, normalizePath };
@@ -0,0 +1,103 @@
1
+ /**
2
+ * 路径处理工具函数
3
+ *
4
+ * @description 提供跨平台路径规范化、扩展名过滤、路径排除匹配等通用功能,
5
+ * 供多个插件复用,避免重复实现。
6
+ */
7
+ /**
8
+ * 将路径中的反斜杠转换为正斜杠,确保跨平台一致性
9
+ *
10
+ * @param {string} filePath - 待规范化的文件路径
11
+ * @returns {string} 使用正斜杠的路径字符串
12
+ *
13
+ * @description Windows 系统下路径使用反斜杠 `\`,而 Unix 系统使用正斜杠 `/`。
14
+ * 统一转换为正斜杠可避免跨平台路径比较失败。
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * normalizePath('assets\\index-abc123.js')
19
+ * // 'assets/index-abc123.js'
20
+ *
21
+ * normalizePath('assets/index.js')
22
+ * // 'assets/index.js'
23
+ * ```
24
+ */
25
+ declare function normalizePath(filePath: string): string;
26
+ /**
27
+ * 检查文件扩展名是否通过包含/排除过滤条件
28
+ *
29
+ * @param {string} ext - 文件扩展名(小写,含点号,如 `.js`)
30
+ * @param {object} options - 过滤选项
31
+ * @param {string[]} [options.includeExtensions] - 包含的扩展名列表(为空则包含所有)
32
+ * @param {string[]} [options.excludeExtensions] - 排除的扩展名列表
33
+ * @returns {boolean} 扩展名是否通过过滤(`true` 表示应包含该文件)
34
+ *
35
+ * @description 按以下优先级判断:
36
+ * 1. 如果 `excludeExtensions` 非空且扩展名在其中,返回 `false`
37
+ * 2. 如果 `includeExtensions` 非空且扩展名不在其中,返回 `false`
38
+ * 3. 其余情况返回 `true`
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * isExtensionIncluded('.js', { includeExtensions: ['.js', '.css'], excludeExtensions: [] })
43
+ * // true
44
+ *
45
+ * isExtensionIncluded('.map', { includeExtensions: [], excludeExtensions: ['.map'] })
46
+ * // false
47
+ *
48
+ * isExtensionIncluded('.js', { includeExtensions: [], excludeExtensions: [] })
49
+ * // true(两个列表均为空,包含所有)
50
+ * ```
51
+ */
52
+ declare function isExtensionIncluded(ext: string, options: {
53
+ includeExtensions?: string[];
54
+ excludeExtensions?: string[];
55
+ }): boolean;
56
+ /**
57
+ * 检查文件路径是否匹配排除路径列表
58
+ *
59
+ * @param {string} relativePath - 文件的相对路径(应先使用 {@link normalizePath} 规范化)
60
+ * @param {string[]} excludePaths - 排除路径列表
61
+ * @param {object} [options] - 匹配选项
62
+ * @param {'simple' | 'segment'} [options.matchMode='simple'] - 匹配模式:
63
+ * - `'simple'`:简单的 startsWith / includes 匹配
64
+ * - `'segment'`:基于路径段边界的精确匹配,避免子字符串误匹配
65
+ * @returns {boolean} 路径是否应被排除(`true` 表示应排除)
66
+ *
67
+ * @description 根据匹配模式检查路径是否命中排除列表:
68
+ * - **simple 模式**:路径以排除项开头或包含排除项即命中
69
+ * - **segment 模式**:基于路径段边界匹配,确保 `excludePaths: ['test']` 不会误排除 `testdata/`
70
+ *
71
+ * 路径比较前会自动调用 {@link normalizePath} 统一分隔符。
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * isPathExcluded('assets/test/file.js', ['test'])
76
+ * // true(simple 模式,默认)
77
+ *
78
+ * isPathExcluded('testdata/file.js', ['test'], { matchMode: 'segment' })
79
+ * // false(segment 模式,'testdata' 不等于路径段 'test')
80
+ *
81
+ * isPathExcluded('assets/test/file.js', ['test'], { matchMode: 'segment' })
82
+ * // true('test' 匹配路径段)
83
+ * ```
84
+ */
85
+ declare function isPathExcluded(relativePath: string, excludePaths: string[], options?: {
86
+ matchMode?: 'simple' | 'segment';
87
+ }): boolean;
88
+ /**
89
+ * 检查扩展名是否为已压缩格式
90
+ *
91
+ * @param {string} ext - 文件扩展名(小写,含点号)
92
+ * @returns {boolean} 是否为已压缩格式(`.gz` 或 `.br`)
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * isPreCompressed('.gz') // true
97
+ * isPreCompressed('.br') // true
98
+ * isPreCompressed('.js') // false
99
+ * ```
100
+ */
101
+ declare function isPreCompressed(ext: string): boolean;
102
+
103
+ export { isExtensionIncluded, isPathExcluded, isPreCompressed, normalizePath };
@@ -0,0 +1,103 @@
1
+ /**
2
+ * 路径处理工具函数
3
+ *
4
+ * @description 提供跨平台路径规范化、扩展名过滤、路径排除匹配等通用功能,
5
+ * 供多个插件复用,避免重复实现。
6
+ */
7
+ /**
8
+ * 将路径中的反斜杠转换为正斜杠,确保跨平台一致性
9
+ *
10
+ * @param {string} filePath - 待规范化的文件路径
11
+ * @returns {string} 使用正斜杠的路径字符串
12
+ *
13
+ * @description Windows 系统下路径使用反斜杠 `\`,而 Unix 系统使用正斜杠 `/`。
14
+ * 统一转换为正斜杠可避免跨平台路径比较失败。
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * normalizePath('assets\\index-abc123.js')
19
+ * // 'assets/index-abc123.js'
20
+ *
21
+ * normalizePath('assets/index.js')
22
+ * // 'assets/index.js'
23
+ * ```
24
+ */
25
+ declare function normalizePath(filePath: string): string;
26
+ /**
27
+ * 检查文件扩展名是否通过包含/排除过滤条件
28
+ *
29
+ * @param {string} ext - 文件扩展名(小写,含点号,如 `.js`)
30
+ * @param {object} options - 过滤选项
31
+ * @param {string[]} [options.includeExtensions] - 包含的扩展名列表(为空则包含所有)
32
+ * @param {string[]} [options.excludeExtensions] - 排除的扩展名列表
33
+ * @returns {boolean} 扩展名是否通过过滤(`true` 表示应包含该文件)
34
+ *
35
+ * @description 按以下优先级判断:
36
+ * 1. 如果 `excludeExtensions` 非空且扩展名在其中,返回 `false`
37
+ * 2. 如果 `includeExtensions` 非空且扩展名不在其中,返回 `false`
38
+ * 3. 其余情况返回 `true`
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * isExtensionIncluded('.js', { includeExtensions: ['.js', '.css'], excludeExtensions: [] })
43
+ * // true
44
+ *
45
+ * isExtensionIncluded('.map', { includeExtensions: [], excludeExtensions: ['.map'] })
46
+ * // false
47
+ *
48
+ * isExtensionIncluded('.js', { includeExtensions: [], excludeExtensions: [] })
49
+ * // true(两个列表均为空,包含所有)
50
+ * ```
51
+ */
52
+ declare function isExtensionIncluded(ext: string, options: {
53
+ includeExtensions?: string[];
54
+ excludeExtensions?: string[];
55
+ }): boolean;
56
+ /**
57
+ * 检查文件路径是否匹配排除路径列表
58
+ *
59
+ * @param {string} relativePath - 文件的相对路径(应先使用 {@link normalizePath} 规范化)
60
+ * @param {string[]} excludePaths - 排除路径列表
61
+ * @param {object} [options] - 匹配选项
62
+ * @param {'simple' | 'segment'} [options.matchMode='simple'] - 匹配模式:
63
+ * - `'simple'`:简单的 startsWith / includes 匹配
64
+ * - `'segment'`:基于路径段边界的精确匹配,避免子字符串误匹配
65
+ * @returns {boolean} 路径是否应被排除(`true` 表示应排除)
66
+ *
67
+ * @description 根据匹配模式检查路径是否命中排除列表:
68
+ * - **simple 模式**:路径以排除项开头或包含排除项即命中
69
+ * - **segment 模式**:基于路径段边界匹配,确保 `excludePaths: ['test']` 不会误排除 `testdata/`
70
+ *
71
+ * 路径比较前会自动调用 {@link normalizePath} 统一分隔符。
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * isPathExcluded('assets/test/file.js', ['test'])
76
+ * // true(simple 模式,默认)
77
+ *
78
+ * isPathExcluded('testdata/file.js', ['test'], { matchMode: 'segment' })
79
+ * // false(segment 模式,'testdata' 不等于路径段 'test')
80
+ *
81
+ * isPathExcluded('assets/test/file.js', ['test'], { matchMode: 'segment' })
82
+ * // true('test' 匹配路径段)
83
+ * ```
84
+ */
85
+ declare function isPathExcluded(relativePath: string, excludePaths: string[], options?: {
86
+ matchMode?: 'simple' | 'segment';
87
+ }): boolean;
88
+ /**
89
+ * 检查扩展名是否为已压缩格式
90
+ *
91
+ * @param {string} ext - 文件扩展名(小写,含点号)
92
+ * @returns {boolean} 是否为已压缩格式(`.gz` 或 `.br`)
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * isPreCompressed('.gz') // true
97
+ * isPreCompressed('.br') // true
98
+ * isPreCompressed('.js') // false
99
+ * ```
100
+ */
101
+ declare function isPreCompressed(ext: string): boolean;
102
+
103
+ export { isExtensionIncluded, isPathExcluded, isPreCompressed, normalizePath };
@@ -0,0 +1 @@
1
+ function i(n){return n.replace(/\\/g,"/")}function o(n,s){const{includeExtensions:r=[],excludeExtensions:e=[]}=s;return!(e.length>0&&e.includes(n)||r.length>0&&!r.includes(n))}function l(n,s,r={}){if(s.length===0)return!1;const e=i(n),{matchMode:u="simple"}=r;for(const c of s){const t=i(c);if(u==="segment"){if(e.startsWith(t+"/")||e===t||e.includes("/"+t+"/")||e.endsWith("/"+t))return!0}else if(e.startsWith(t)||e.includes(t))return!0}return!1}function d(n){return n===".gz"||n===".br"}export{o as isExtensionIncluded,l as isPathExcluded,d as isPreCompressed,i as normalizePath};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";const common_format_index=require("./common/format/index.cjs"),common_fs_index=require("./common/fs/index.cjs"),common_html_index=require("./common/html/index.cjs"),common_script_index=require("./common/script/index.cjs"),common_ui_index=require("./common/ui/index.cjs"),validator=require("./shared/vite-plugin.Bcg6RW2N.cjs"),common_validation_index=require("./common/validation/index.cjs"),factory_index=require("./factory/index.cjs"),logger_index=require("./logger/index.cjs"),plugins_autoImport_index=require("./plugins/autoImport/index.cjs"),plugins_buildProgress_index=require("./plugins/buildProgress/index.cjs"),plugins_bundleAnalyzer_index=require("./plugins/bundleAnalyzer/index.cjs"),plugins_compressAssets_index=require("./plugins/compressAssets/index.cjs"),plugins_copyFile_index=require("./plugins/copyFile/index.cjs"),plugins_envGuard_index=require("./plugins/envGuard/index.cjs"),plugins_faviconManager_index=require("./plugins/faviconManager/index.cjs"),plugins_generateRouter_index=require("./plugins/generateRouter/index.cjs"),plugins_generateVersion_index=require("./plugins/generateVersion/index.cjs"),plugins_htmlInject_index=require("./plugins/htmlInject/index.cjs"),plugins_loadingManager_index=require("./plugins/loadingManager/index.cjs"),plugins_versionUpdateChecker_index=require("./plugins/versionUpdateChecker/index.cjs"),security=require("./shared/vite-plugin.CcvHfrL8.cjs");require("fs"),require("path"),require("node:fs"),require("node:path"),require("node:zlib"),require("node:util"),require("node:stream/promises"),require("crypto"),exports.formatDate=common_format_index.formatDate,exports.formatFileSize=common_format_index.formatFileSize,exports.getDateFormatParams=common_format_index.getDateFormatParams,exports.parseTemplate=common_format_index.parseTemplate,exports.checkSourceExists=common_fs_index.checkSourceExists,exports.copySourceToTarget=common_fs_index.copySourceToTarget,exports.scanDirectory=common_fs_index.scanDirectory,exports.shouldUpdateFileContent=common_fs_index.shouldUpdateFileContent,exports.writeFileContent=common_fs_index.writeFileContent,exports.writeFileSyncSafely=common_fs_index.writeFileSyncSafely,exports.writeJsonReport=common_fs_index.writeJsonReport,exports.injectBeforeTag=common_html_index.injectBeforeTag,exports.injectHeadAndBody=common_html_index.injectHeadAndBody,exports.makeCallback=common_script_index.makeCallback,exports.ANSI=common_ui_index.ANSI,exports.Validator=validator.Validator,exports.validateCallbackFields=common_validation_index.validateCallbackFields,exports.validateGlobalName=common_validation_index.validateGlobalName,exports.validateNoScriptInTemplate=common_validation_index.validateNoScriptInTemplate,exports.BasePlugin=factory_index.BasePlugin,exports.createPluginFactory=factory_index.createPluginFactory,exports.Logger=logger_index.Logger,exports.autoImport=plugins_autoImport_index.autoImport,exports.buildProgress=plugins_buildProgress_index.buildProgress,exports.bundleAnalyzer=plugins_bundleAnalyzer_index.bundleAnalyzer,exports.compressAssets=plugins_compressAssets_index.compressAssets,exports.copyFile=plugins_copyFile_index.copyFile,exports.envGuard=plugins_envGuard_index.envGuard,exports.faviconManager=plugins_faviconManager_index.faviconManager,exports.generateRouter=plugins_generateRouter_index.generateRouter,exports.generateVersion=plugins_generateVersion_index.generateVersion,exports.htmlInject=plugins_htmlInject_index.htmlInject,exports.loadingManager=plugins_loadingManager_index.loadingManager,exports.versionUpdateChecker=plugins_versionUpdateChecker_index.versionUpdateChecker,exports.escapeHtmlAttr=security.escapeHtmlAttr,exports.sanitizeContent=security.sanitizeContent;
1
+ "use strict";const common_concurrency_index=require("./common/concurrency/index.cjs"),common_format_index=require("./common/format/index.cjs"),common_fs_index=require("./common/fs/index.cjs"),common_html_index=require("./common/html/index.cjs"),common_path_index=require("./common/path/index.cjs"),common_script_index=require("./common/script/index.cjs"),common_ui_index=require("./common/ui/index.cjs"),validator=require("./shared/vite-plugin.Bcg6RW2N.cjs"),common_validation_index=require("./common/validation/index.cjs"),factory_index=require("./factory/index.cjs"),logger_index=require("./logger/index.cjs"),plugins_assetManifest_index=require("./plugins/assetManifest/index.cjs"),plugins_autoImport_index=require("./plugins/autoImport/index.cjs"),plugins_buildProgress_index=require("./plugins/buildProgress/index.cjs"),plugins_bundleAnalyzer_index=require("./plugins/bundleAnalyzer/index.cjs"),plugins_compressAssets_index=require("./plugins/compressAssets/index.cjs"),plugins_copyFile_index=require("./plugins/copyFile/index.cjs"),plugins_envGuard_index=require("./plugins/envGuard/index.cjs"),plugins_faviconManager_index=require("./plugins/faviconManager/index.cjs"),plugins_generateRouter_index=require("./plugins/generateRouter/index.cjs"),plugins_generateVersion_index=require("./plugins/generateVersion/index.cjs"),plugins_htmlInject_index=require("./plugins/htmlInject/index.cjs"),plugins_imageOptimizer_index=require("./plugins/imageOptimizer/index.cjs"),plugins_loadingManager_index=require("./plugins/loadingManager/index.cjs"),plugins_versionUpdateChecker_index=require("./plugins/versionUpdateChecker/index.cjs"),security=require("./shared/vite-plugin.CcvHfrL8.cjs");require("fs"),require("path"),require("node:path"),require("node:fs"),require("node:zlib"),require("node:util"),require("node:stream/promises"),require("crypto"),exports.runWithConcurrency=common_concurrency_index.runWithConcurrency,exports.calcRatio=common_format_index.calcRatio,exports.formatDate=common_format_index.formatDate,exports.formatFileSize=common_format_index.formatFileSize,exports.getDateFormatParams=common_format_index.getDateFormatParams,exports.parseTemplate=common_format_index.parseTemplate,exports.checkSourceExists=common_fs_index.checkSourceExists,exports.copySourceToTarget=common_fs_index.copySourceToTarget,exports.resolveReportPath=common_fs_index.resolveReportPath,exports.scanDirectory=common_fs_index.scanDirectory,exports.shouldUpdateFileContent=common_fs_index.shouldUpdateFileContent,exports.writeFileContent=common_fs_index.writeFileContent,exports.writeFileSyncSafely=common_fs_index.writeFileSyncSafely,exports.writeJsonReport=common_fs_index.writeJsonReport,exports.injectBeforeTag=common_html_index.injectBeforeTag,exports.injectHeadAndBody=common_html_index.injectHeadAndBody,exports.isExtensionIncluded=common_path_index.isExtensionIncluded,exports.isPathExcluded=common_path_index.isPathExcluded,exports.isPreCompressed=common_path_index.isPreCompressed,exports.normalizePath=common_path_index.normalizePath,exports.makeCallback=common_script_index.makeCallback,exports.ANSI=common_ui_index.ANSI,exports.Validator=validator.Validator,exports.validateCallbackFields=common_validation_index.validateCallbackFields,exports.validateGlobalName=common_validation_index.validateGlobalName,exports.validateNoScriptInTemplate=common_validation_index.validateNoScriptInTemplate,exports.BasePlugin=factory_index.BasePlugin,exports.createPluginFactory=factory_index.createPluginFactory,exports.Logger=logger_index.Logger,exports.assetManifest=plugins_assetManifest_index.assetManifest,exports.autoImport=plugins_autoImport_index.autoImport,exports.buildProgress=plugins_buildProgress_index.buildProgress,exports.bundleAnalyzer=plugins_bundleAnalyzer_index.bundleAnalyzer,exports.compressAssets=plugins_compressAssets_index.compressAssets,exports.copyFile=plugins_copyFile_index.copyFile,exports.envGuard=plugins_envGuard_index.envGuard,exports.faviconManager=plugins_faviconManager_index.faviconManager,exports.generateRouter=plugins_generateRouter_index.generateRouter,exports.generateVersion=plugins_generateVersion_index.generateVersion,exports.htmlInject=plugins_htmlInject_index.htmlInject,exports.imageOptimizer=plugins_imageOptimizer_index.imageOptimizer,exports.loadingManager=plugins_loadingManager_index.loadingManager,exports.versionUpdateChecker=plugins_versionUpdateChecker_index.versionUpdateChecker,exports.escapeHtmlAttr=security.escapeHtmlAttr,exports.sanitizeContent=security.sanitizeContent;
package/dist/index.d.cts CHANGED
@@ -1,12 +1,15 @@
1
- export { DateFormatOptions, formatDate, formatFileSize, getDateFormatParams, parseTemplate } from './common/format/index.cjs';
2
- export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport } from './common/fs/index.cjs';
1
+ export { runWithConcurrency } from './common/concurrency/index.cjs';
2
+ export { DateFormatOptions, calcRatio, formatDate, formatFileSize, getDateFormatParams, parseTemplate } from './common/format/index.cjs';
3
+ export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, resolveReportPath, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport } from './common/fs/index.cjs';
3
4
  export { SanitizeRuleOptions, escapeHtmlAttr, injectBeforeTag, injectHeadAndBody, sanitizeContent } from './common/html/index.cjs';
5
+ export { isExtensionIncluded, isPathExcluded, isPreCompressed, normalizePath } from './common/path/index.cjs';
4
6
  export { makeCallback } from './common/script/index.cjs';
5
7
  export { ANSI } from './common/ui/index.cjs';
6
8
  export { V as Validator } from './shared/vite-plugin.DRRlWY8P.cjs';
7
9
  export { validateCallbackFields, validateGlobalName, validateNoScriptInTemplate } from './common/validation/index.cjs';
8
10
  export { BasePlugin, BasePluginOptions, OptionsNormalizer, PluginFactory, PluginWithInstance, createPluginFactory } from './factory/index.cjs';
9
11
  export { Logger } from './logger/index.cjs';
12
+ export { AssetGroup, AssetManifestOptions, AssetManifestResult, AssetMap, CustomFormatter, ManifestOutputFormat, WebpackEntryAsset, WebpackManifestOutput, assetManifest } from './plugins/assetManifest/index.cjs';
10
13
  export { AutoImportOptions, ImportMapping, ResolvedImport, ScannedModule, TransformResult, autoImport } from './plugins/autoImport/index.cjs';
11
14
  export { BuildPhase, BuildProgressOptions, ProgressFormat, ProgressTheme, buildProgress } from './plugins/buildProgress/index.cjs';
12
15
  export { BundleAnalysisResult, BundleAnalyzerOptions, BundleOutputFormat, ChunkStats, ComparisonDiff, FileTypeDistribution, ModuleStats, SizeWarning, bundleAnalyzer } from './plugins/bundleAnalyzer/index.cjs';
@@ -17,6 +20,7 @@ export { FaviconManagerOptions, Icon, faviconManager } from './plugins/faviconMa
17
20
  export { GenerateRouterOptions, NameStrategy, OutputFormat, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig, generateRouter } from './plugins/generateRouter/index.cjs';
18
21
  export { GenerateVersionOptions, OutputType, VersionFormat, VersionInfo, generateVersion } from './plugins/generateVersion/index.cjs';
19
22
  export { HtmlInjectOptions, InjectRule, InjectionLogEntry, htmlInject } from './plugins/htmlInject/index.cjs';
23
+ export { ConvertMapping, FormatQualityOptions, ImageFormat, ImageOptimizeStats, ImageOptimizeSummary, ImageOptimizerOptions, SvgoOptions, SvgoPlugin, imageOptimizer } from './plugins/imageOptimizer/index.cjs';
20
24
  export { AutoBindMode, AutoHideOn, DebounceHide, DelayShow, LoadingCallbacks, LoadingManager, LoadingManagerOptions, LoadingPosition, LoadingStyle, MinDisplayTime, RequestFilter, SpinnerType, TransitionConfig, loadingManager } from './plugins/loadingManager/index.cjs';
21
25
  export { PromptStyle, VersionSource, VersionUpdateCheckerOptions, versionUpdateChecker } from './plugins/versionUpdateChecker/index.cjs';
22
26
  export { C as ConditionType, D as DualInjectResult, H as HtmlInjectResult, I as InjectCondition, a as InjectPosition, S as SecurityConfig, b as SelectorMatch } from './shared/vite-plugin.BI9taN75.cjs';
package/dist/index.d.mts CHANGED
@@ -1,12 +1,15 @@
1
- export { DateFormatOptions, formatDate, formatFileSize, getDateFormatParams, parseTemplate } from './common/format/index.mjs';
2
- export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport } from './common/fs/index.mjs';
1
+ export { runWithConcurrency } from './common/concurrency/index.mjs';
2
+ export { DateFormatOptions, calcRatio, formatDate, formatFileSize, getDateFormatParams, parseTemplate } from './common/format/index.mjs';
3
+ export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, resolveReportPath, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport } from './common/fs/index.mjs';
3
4
  export { SanitizeRuleOptions, escapeHtmlAttr, injectBeforeTag, injectHeadAndBody, sanitizeContent } from './common/html/index.mjs';
5
+ export { isExtensionIncluded, isPathExcluded, isPreCompressed, normalizePath } from './common/path/index.mjs';
4
6
  export { makeCallback } from './common/script/index.mjs';
5
7
  export { ANSI } from './common/ui/index.mjs';
6
8
  export { V as Validator } from './shared/vite-plugin.DRRlWY8P.mjs';
7
9
  export { validateCallbackFields, validateGlobalName, validateNoScriptInTemplate } from './common/validation/index.mjs';
8
10
  export { BasePlugin, BasePluginOptions, OptionsNormalizer, PluginFactory, PluginWithInstance, createPluginFactory } from './factory/index.mjs';
9
11
  export { Logger } from './logger/index.mjs';
12
+ export { AssetGroup, AssetManifestOptions, AssetManifestResult, AssetMap, CustomFormatter, ManifestOutputFormat, WebpackEntryAsset, WebpackManifestOutput, assetManifest } from './plugins/assetManifest/index.mjs';
10
13
  export { AutoImportOptions, ImportMapping, ResolvedImport, ScannedModule, TransformResult, autoImport } from './plugins/autoImport/index.mjs';
11
14
  export { BuildPhase, BuildProgressOptions, ProgressFormat, ProgressTheme, buildProgress } from './plugins/buildProgress/index.mjs';
12
15
  export { BundleAnalysisResult, BundleAnalyzerOptions, BundleOutputFormat, ChunkStats, ComparisonDiff, FileTypeDistribution, ModuleStats, SizeWarning, bundleAnalyzer } from './plugins/bundleAnalyzer/index.mjs';
@@ -17,6 +20,7 @@ export { FaviconManagerOptions, Icon, faviconManager } from './plugins/faviconMa
17
20
  export { GenerateRouterOptions, NameStrategy, OutputFormat, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig, generateRouter } from './plugins/generateRouter/index.mjs';
18
21
  export { GenerateVersionOptions, OutputType, VersionFormat, VersionInfo, generateVersion } from './plugins/generateVersion/index.mjs';
19
22
  export { HtmlInjectOptions, InjectRule, InjectionLogEntry, htmlInject } from './plugins/htmlInject/index.mjs';
23
+ export { ConvertMapping, FormatQualityOptions, ImageFormat, ImageOptimizeStats, ImageOptimizeSummary, ImageOptimizerOptions, SvgoOptions, SvgoPlugin, imageOptimizer } from './plugins/imageOptimizer/index.mjs';
20
24
  export { AutoBindMode, AutoHideOn, DebounceHide, DelayShow, LoadingCallbacks, LoadingManager, LoadingManagerOptions, LoadingPosition, LoadingStyle, MinDisplayTime, RequestFilter, SpinnerType, TransitionConfig, loadingManager } from './plugins/loadingManager/index.mjs';
21
25
  export { PromptStyle, VersionSource, VersionUpdateCheckerOptions, versionUpdateChecker } from './plugins/versionUpdateChecker/index.mjs';
22
26
  export { C as ConditionType, D as DualInjectResult, H as HtmlInjectResult, I as InjectCondition, a as InjectPosition, S as SecurityConfig, b as SelectorMatch } from './shared/vite-plugin.BI9taN75.mjs';
package/dist/index.d.ts CHANGED
@@ -1,12 +1,15 @@
1
- export { DateFormatOptions, formatDate, formatFileSize, getDateFormatParams, parseTemplate } from './common/format/index.js';
2
- export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport } from './common/fs/index.js';
1
+ export { runWithConcurrency } from './common/concurrency/index.js';
2
+ export { DateFormatOptions, calcRatio, formatDate, formatFileSize, getDateFormatParams, parseTemplate } from './common/format/index.js';
3
+ export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, resolveReportPath, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport } from './common/fs/index.js';
3
4
  export { SanitizeRuleOptions, escapeHtmlAttr, injectBeforeTag, injectHeadAndBody, sanitizeContent } from './common/html/index.js';
5
+ export { isExtensionIncluded, isPathExcluded, isPreCompressed, normalizePath } from './common/path/index.js';
4
6
  export { makeCallback } from './common/script/index.js';
5
7
  export { ANSI } from './common/ui/index.js';
6
8
  export { V as Validator } from './shared/vite-plugin.DRRlWY8P.js';
7
9
  export { validateCallbackFields, validateGlobalName, validateNoScriptInTemplate } from './common/validation/index.js';
8
10
  export { BasePlugin, BasePluginOptions, OptionsNormalizer, PluginFactory, PluginWithInstance, createPluginFactory } from './factory/index.js';
9
11
  export { Logger } from './logger/index.js';
12
+ export { AssetGroup, AssetManifestOptions, AssetManifestResult, AssetMap, CustomFormatter, ManifestOutputFormat, WebpackEntryAsset, WebpackManifestOutput, assetManifest } from './plugins/assetManifest/index.js';
10
13
  export { AutoImportOptions, ImportMapping, ResolvedImport, ScannedModule, TransformResult, autoImport } from './plugins/autoImport/index.js';
11
14
  export { BuildPhase, BuildProgressOptions, ProgressFormat, ProgressTheme, buildProgress } from './plugins/buildProgress/index.js';
12
15
  export { BundleAnalysisResult, BundleAnalyzerOptions, BundleOutputFormat, ChunkStats, ComparisonDiff, FileTypeDistribution, ModuleStats, SizeWarning, bundleAnalyzer } from './plugins/bundleAnalyzer/index.js';
@@ -17,6 +20,7 @@ export { FaviconManagerOptions, Icon, faviconManager } from './plugins/faviconMa
17
20
  export { GenerateRouterOptions, NameStrategy, OutputFormat, RouteConfig, RouteMeta, UniAppPageConfig, UniAppPagesJson, UniAppTabBarConfig, generateRouter } from './plugins/generateRouter/index.js';
18
21
  export { GenerateVersionOptions, OutputType, VersionFormat, VersionInfo, generateVersion } from './plugins/generateVersion/index.js';
19
22
  export { HtmlInjectOptions, InjectRule, InjectionLogEntry, htmlInject } from './plugins/htmlInject/index.js';
23
+ export { ConvertMapping, FormatQualityOptions, ImageFormat, ImageOptimizeStats, ImageOptimizeSummary, ImageOptimizerOptions, SvgoOptions, SvgoPlugin, imageOptimizer } from './plugins/imageOptimizer/index.js';
20
24
  export { AutoBindMode, AutoHideOn, DebounceHide, DelayShow, LoadingCallbacks, LoadingManager, LoadingManagerOptions, LoadingPosition, LoadingStyle, MinDisplayTime, RequestFilter, SpinnerType, TransitionConfig, loadingManager } from './plugins/loadingManager/index.js';
21
25
  export { PromptStyle, VersionSource, VersionUpdateCheckerOptions, versionUpdateChecker } from './plugins/versionUpdateChecker/index.js';
22
26
  export { C as ConditionType, D as DualInjectResult, H as HtmlInjectResult, I as InjectCondition, a as InjectPosition, S as SecurityConfig, b as SelectorMatch } from './shared/vite-plugin.BI9taN75.js';
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export{formatDate,formatFileSize,getDateFormatParams,parseTemplate}from"./common/format/index.mjs";export{checkSourceExists,copySourceToTarget,scanDirectory,shouldUpdateFileContent,writeFileContent,writeFileSyncSafely,writeJsonReport}from"./common/fs/index.mjs";export{injectBeforeTag,injectHeadAndBody}from"./common/html/index.mjs";export{makeCallback}from"./common/script/index.mjs";export{ANSI}from"./common/ui/index.mjs";export{V as Validator}from"./shared/vite-plugin.DcExl6jd.mjs";export{validateCallbackFields,validateGlobalName,validateNoScriptInTemplate}from"./common/validation/index.mjs";export{BasePlugin,createPluginFactory}from"./factory/index.mjs";export{Logger}from"./logger/index.mjs";export{autoImport}from"./plugins/autoImport/index.mjs";export{buildProgress}from"./plugins/buildProgress/index.mjs";export{bundleAnalyzer}from"./plugins/bundleAnalyzer/index.mjs";export{compressAssets}from"./plugins/compressAssets/index.mjs";export{copyFile}from"./plugins/copyFile/index.mjs";export{envGuard}from"./plugins/envGuard/index.mjs";export{faviconManager}from"./plugins/faviconManager/index.mjs";export{generateRouter}from"./plugins/generateRouter/index.mjs";export{generateVersion}from"./plugins/generateVersion/index.mjs";export{htmlInject}from"./plugins/htmlInject/index.mjs";export{loadingManager}from"./plugins/loadingManager/index.mjs";export{versionUpdateChecker}from"./plugins/versionUpdateChecker/index.mjs";export{e as escapeHtmlAttr,s as sanitizeContent}from"./shared/vite-plugin.CuXEJAWX.mjs";import"fs";import"path";import"node:fs";import"node:path";import"node:zlib";import"node:util";import"node:stream/promises";import"crypto";
1
+ export{runWithConcurrency}from"./common/concurrency/index.mjs";export{calcRatio,formatDate,formatFileSize,getDateFormatParams,parseTemplate}from"./common/format/index.mjs";export{checkSourceExists,copySourceToTarget,resolveReportPath,scanDirectory,shouldUpdateFileContent,writeFileContent,writeFileSyncSafely,writeJsonReport}from"./common/fs/index.mjs";export{injectBeforeTag,injectHeadAndBody}from"./common/html/index.mjs";export{isExtensionIncluded,isPathExcluded,isPreCompressed,normalizePath}from"./common/path/index.mjs";export{makeCallback}from"./common/script/index.mjs";export{ANSI}from"./common/ui/index.mjs";export{V as Validator}from"./shared/vite-plugin.DcExl6jd.mjs";export{validateCallbackFields,validateGlobalName,validateNoScriptInTemplate}from"./common/validation/index.mjs";export{BasePlugin,createPluginFactory}from"./factory/index.mjs";export{Logger}from"./logger/index.mjs";export{assetManifest}from"./plugins/assetManifest/index.mjs";export{autoImport}from"./plugins/autoImport/index.mjs";export{buildProgress}from"./plugins/buildProgress/index.mjs";export{bundleAnalyzer}from"./plugins/bundleAnalyzer/index.mjs";export{compressAssets}from"./plugins/compressAssets/index.mjs";export{copyFile}from"./plugins/copyFile/index.mjs";export{envGuard}from"./plugins/envGuard/index.mjs";export{faviconManager}from"./plugins/faviconManager/index.mjs";export{generateRouter}from"./plugins/generateRouter/index.mjs";export{generateVersion}from"./plugins/generateVersion/index.mjs";export{htmlInject}from"./plugins/htmlInject/index.mjs";export{imageOptimizer}from"./plugins/imageOptimizer/index.mjs";export{loadingManager}from"./plugins/loadingManager/index.mjs";export{versionUpdateChecker}from"./plugins/versionUpdateChecker/index.mjs";export{e as escapeHtmlAttr,s as sanitizeContent}from"./shared/vite-plugin.CuXEJAWX.mjs";import"fs";import"path";import"node:path";import"node:fs";import"node:zlib";import"node:util";import"node:stream/promises";import"crypto";
@@ -0,0 +1 @@
1
+ "use strict";const l=require("node:path"),u$2=require("node:fs"),factory_index=require("../../factory/index.cjs"),common_fs_index=require("../../common/fs/index.cjs"),common_path_index=require("../../common/path/index.cjs"),common_html_index=require("../../common/html/index.cjs"),common_validation_index=require("../../common/validation/index.cjs");require("../../logger/index.cjs"),require("../../shared/vite-plugin.Bcg6RW2N.cjs"),require("fs"),require("path"),require("../../common/concurrency/index.cjs"),require("../../shared/vite-plugin.CcvHfrL8.cjs");function _interopDefaultCompat(s){return s&&typeof s=="object"&&"default"in s?s.default:s}const l__default=_interopDefaultCompat(l),u__default=_interopDefaultCompat(u$2);function shouldIncludeAsset(s,t,e){const n=common_path_index.normalizePath(s);if(!common_path_index.isExtensionIncluded(t,{includeExtensions:e.includeExtensions,excludeExtensions:e.excludeExtensions})||common_path_index.isPathExcluded(s,e.excludePaths,{matchMode:"segment"}))return!1;const o=common_path_index.normalizePath(e.outputFile);return!(n===o||n.endsWith("/"+o)||n.endsWith("manifest.json")||n.endsWith("asset-manifest.json")||common_path_index.isPreCompressed(t))}async function scanOutputDirectory(s,t){return(await common_fs_index.scanDirectory(s,{filter:(e,n,o)=>{const h=common_path_index.normalizePath(l__default.relative(s,e));return shouldIncludeAsset(h,n,t)}})).map(e=>({filePath:e.filePath,relativePath:common_path_index.normalizePath(l__default.relative(s,e.filePath)),size:e.size,ext:e.extension}))}function buildAssetMap(s,t,e){const n={},o=t.endsWith("/")?t:t+"/";for(const h of s){const c=extractOriginalKey(h.relativePath),r=o+h.relativePath;n[c]!==void 0&&n[c]!==r?(n[h.relativePath]=r,e?.(`\u8D44\u6E90\u952E\u540D\u51B2\u7A81: "${c}" \u5DF2\u88AB ${n[c]} \u5360\u7528\uFF0C"${h.relativePath}" \u5C06\u4F7F\u7528\u5B8C\u6574\u8DEF\u5F84\u4F5C\u4E3A\u952E`)):n[c]=r}return n}function extractOriginalKey(s){const t=/[-.]([0-9a-f]{6,20})(?=\.)/g;return s.replace(t,"")}function formatManifest(s,t,e,n,o){switch(t){case"vite":return a(s,n,o);case"webpack":return i(s,o);case"custom":return u$1(s,e);default:return a(s,n,o)}}function a(s,t,e){const n={version:"1.0",timestamp:new Date().toISOString(),publicPath:t,assets:s};return e&&e.length>0&&(n.groups=e),n}function i(s,t){return t&&t.length>0?{entries:t.map(e=>({name:e.entry,files:[...e.assets.js,...e.assets.css,...e.assets.other]})),assets:s}:{entries:[{name:"main",files:Object.values(s)}],assets:s}}function u$1(s,t){if(!t)throw new Error('outputFormat \u4E3A "custom" \u65F6\uFF0CcustomFormatter \u4E0D\u80FD\u4E3A\u7A7A');return t(s)}function groupAssetsByEntry(s,t){const e=new Map,n=new Set,o=s.filter(d);for(const r of o){const p=f(r.relativePath);e.has(p)||e.set(p,{entry:p,assets:{js:[],css:[],other:[]}});const g=e.get(p),E=t[r.relativePath]||r.relativePath;u(g,E,r.ext),n.add(r.relativePath)}const h=s.filter(r=>!n.has(r.relativePath)&&!A(r));for(const r of h){const p=m(r,o),g=p?f(p.relativePath):"_shared";e.has(g)||e.set(g,{entry:g,assets:{js:[],css:[],other:[]}});const E=e.get(g),v=t[r.relativePath]||r.relativePath;u(E,v,r.ext),n.add(r.relativePath)}const c=s.filter(r=>!n.has(r.relativePath));if(c.length>0){e.has("_shared")||e.set("_shared",{entry:"_shared",assets:{js:[],css:[],other:[]}});const r=e.get("_shared");for(const p of c){const g=t[p.relativePath]||p.relativePath;u(r,g,p.ext)}}return Array.from(e.values())}function d(s){const{relativePath:t,ext:e}=s,n=t.split("/").pop()||"";return!!(e===".html"||(e===".js"||e===".mjs")&&(n.startsWith("entry-")||n.startsWith("main")||!t.includes("/")))}function A(s){return[".png",".jpg",".jpeg",".gif",".svg",".webp",".ico",".woff",".woff2",".ttf",".eot",".map"].includes(s.ext)}function f(s){let t=(s.split("/").pop()||"").replace(/\.[^.]+$/,"");return t.startsWith("entry-")&&(t=t.slice(6)),t.replace(/[-.][0-9a-f]{6,20}$/,"")||t}function m(s,t){const e=s.relativePath.split("/").slice(0,-1).join("/"),n=(s.relativePath.split("/").pop()||"").replace(/\.[^.]+$/,"").replace(/[-.][0-9a-f]{6,20}$/,"");let o=null,h=0;for(const c of t){const r=c.relativePath.split("/").slice(0,-1).join("/"),p=f(c.relativePath);if(e===r)return c;n.startsWith(p)&&p.length>h&&(o=c,h=p.length)}return o}function u(s,t,e){e===".js"||e===".mjs"?s.assets.js.push(t):e===".css"?s.assets.css.push(t):s.assets.other.push(t)}function generateRuntimeScript(s,t){const e=JSON.stringify(s).replace(/<\/script>/gi,"<\\/script>");return`<script>Object.defineProperty(window,"${t}",{value:Object.freeze(${e}),writable:false,configurable:false})<\/script>`}function injectRuntimeManifest(s,t,e){const n=generateRuntimeScript(t,e);return common_html_index.injectBeforeTag(s,"</head>",n)}class F extends factory_index.BasePlugin{manifest=null;assetMap={};groups=null;getDefaultOptions(){return{outputFormat:"vite",outputFile:"manifest.json",includeExtensions:[],publicPath:"/",injectRuntime:!1,runtimeGlobalName:"__ASSET_MANIFEST__",customFormatter:null,groupByEntry:!1,excludeExtensions:[".map",".gz",".br"],excludePaths:[]}}validateOptions(){this.validator.field("outputFormat").enum(["vite","webpack","custom"]).field("outputFile").custom(t=>typeof t=="string"&&t.length>0,"outputFile \u5FC5\u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32").field("publicPath").custom(t=>typeof t=="string"&&t.length>0,"publicPath \u5FC5\u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32").field("injectRuntime").boolean().field("runtimeGlobalName").custom(t=>typeof t=="string"&&t.length>0,"runtimeGlobalName \u5FC5\u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32").field("groupByEntry").boolean().field("customFormatter").custom(t=>this.options.outputFormat!=="custom"||typeof t=="function",'outputFormat \u4E3A "custom" \u65F6\uFF0CcustomFormatter \u5FC5\u987B\u4E3A\u51FD\u6570').validate(),common_validation_index.validateGlobalName(this.options.runtimeGlobalName,"runtimeGlobalName")}getPluginName(){return"asset-manifest"}getEnforce(){return"post"}addPluginHooks(t){t.writeBundle={order:"post",handler:async()=>{await this.safeExecute(()=>this.generateManifest(),"\u751F\u6210\u8D44\u6E90\u6E05\u5355")}}}async generateManifest(){if(!this.viteConfig)return;const t=this.viteConfig.build.outDir,e=Date.now();this.logger.info(`\u5F00\u59CB\u626B\u63CF\u6784\u5EFA\u4EA7\u7269\u76EE\u5F55: ${t}`);const n=await scanOutputDirectory(t,this.options);if(n.length===0){this.logger.info("\u672A\u627E\u5230\u9700\u8981\u8BB0\u5F55\u7684\u8D44\u6E90\u6587\u4EF6");return}this.assetMap=buildAssetMap(n,this.options.publicPath,r=>{this.logger.warn(r)}),this.options.groupByEntry&&(this.groups=groupAssetsByEntry(n,this.assetMap));const o=formatManifest(this.assetMap,this.options.outputFormat,this.options.customFormatter,this.options.publicPath,this.groups??void 0),h=l__default.isAbsolute(this.options.outputFile)?this.options.outputFile:l__default.join(t,this.options.outputFile);await common_fs_index.writeFileContent(h,JSON.stringify(o,null,2)),this.options.outputFormat==="vite"&&(this.manifest=o),this.options.injectRuntime&&await this.injectRuntimeToHtmlFiles(t);const c=Date.now()-e;this.logStats(n.length,c)}async injectRuntimeToHtmlFiles(t){if(!this.manifest&&Object.keys(this.assetMap).length===0){this.logger.warn("\u8D44\u6E90\u6E05\u5355\u5C1A\u672A\u751F\u6210\uFF0C\u8DF3\u8FC7\u8FD0\u884C\u65F6\u6CE8\u5165");return}const e=this.manifest?.assets||this.assetMap,n=await this.findHtmlFiles(t);if(n.length===0){this.logger.warn("\u672A\u627E\u5230 HTML \u6587\u4EF6\uFF0C\u8FD0\u884C\u65F6\u6E05\u5355\u6CE8\u5165\u8DF3\u8FC7");return}for(const o of n)try{const h=await u__default.promises.readFile(o,"utf-8"),c=injectRuntimeManifest(h,e,this.options.runtimeGlobalName);c.injected?(await common_fs_index.writeFileContent(o,c.html),this.logger.info(`\u8FD0\u884C\u65F6\u6E05\u5355\u5DF2\u6CE8\u5165\u5230: ${l__default.relative(t,o)}`)):this.logger.warn(`\u672A\u627E\u5230 </head> \u6807\u7B7E\uFF0C\u8DF3\u8FC7\u6CE8\u5165: ${l__default.relative(t,o)}`)}catch(h){this.logger.error(`\u6CE8\u5165\u8FD0\u884C\u65F6\u6E05\u5355\u5931\u8D25: ${o} - ${h instanceof Error?h.message:String(h)}`)}this.logger.info(`\u8FD0\u884C\u65F6\u6E05\u5355\u5168\u5C40\u53D8\u91CF: ${this.options.runtimeGlobalName}`)}async findHtmlFiles(t){const e=[];async function n(o){const h=await u__default.promises.readdir(o,{withFileTypes:!0});for(const c of h){const r=l__default.join(o,c.name);c.isDirectory()?await n(r):c.isFile()&&c.name.endsWith(".html")&&e.push(r)}}return await n(t),e}logStats(t,e){const n=Object.keys(this.assetMap).length;this.logger.success(`\u8D44\u6E90\u6E05\u5355\u5DF2\u751F\u6210: ${t} \u4E2A\u8D44\u6E90\u6587\u4EF6\uFF0C${n} \u6761\u6620\u5C04\u8BB0\u5F55`,`\u683C\u5F0F: ${this.options.outputFormat}\uFF0C\u8F93\u51FA: ${this.options.outputFile}\uFF0C\u8017\u65F6: ${e}ms`),this.groups&&this.groups.length>0&&this.logger.info(`\u5165\u53E3\u5206\u7EC4: ${this.groups.map(o=>`${o.entry}(${o.assets.js.length+o.assets.css.length+o.assets.other.length})`).join(", ")}`)}getAssetMap(){return{...this.assetMap}}getManifest(){return this.manifest}getGroups(){return this.groups}}const assetManifest=factory_index.createPluginFactory(F);exports.assetManifest=assetManifest;