@meng-xi/vite-plugin 0.1.6 → 0.1.7
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.
- package/README-en.md +5 -1
- package/README.md +5 -1
- package/dist/common/index.cjs +1 -1
- package/dist/common/index.d.cts +1 -0
- package/dist/common/index.d.mts +1 -0
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.mjs +1 -1
- package/dist/common/path/index.cjs +1 -0
- package/dist/common/path/index.d.cts +103 -0
- package/dist/common/path/index.d.mts +103 -0
- package/dist/common/path/index.d.ts +103 -0
- package/dist/common/path/index.mjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +1 -1
- package/dist/plugins/assetManifest/index.cjs +1 -0
- package/dist/plugins/assetManifest/index.d.cts +162 -0
- package/dist/plugins/assetManifest/index.d.mts +162 -0
- package/dist/plugins/assetManifest/index.d.ts +162 -0
- package/dist/plugins/assetManifest/index.mjs +1 -0
- package/dist/plugins/bundleAnalyzer/index.cjs +1 -1
- package/dist/plugins/bundleAnalyzer/index.mjs +2 -2
- package/dist/plugins/compressAssets/index.cjs +1 -1
- package/dist/plugins/compressAssets/index.mjs +1 -1
- package/dist/plugins/htmlInject/index.cjs +7 -7
- package/dist/plugins/htmlInject/index.mjs +2 -2
- package/dist/plugins/index.cjs +1 -1
- package/dist/plugins/index.d.cts +1 -0
- package/dist/plugins/index.d.mts +1 -0
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.mjs +1 -1
- package/package.json +11 -1
package/README-en.md
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
- **Ready to Use** - 12 practical plugins covering auto-import, build progress, bundle analysis & compression, file copying, environment variable validation, route generation, version management, HTML injection, favicon
|
|
19
19
|
management, global Loading, and more
|
|
20
20
|
- **Plugin Development Framework** - Exports core components like BasePlugin, Logger, and Validator to quickly build custom Vite plugins
|
|
21
|
-
- **Common Utility Library** - Built-in
|
|
21
|
+
- **Common Utility Library** - Built-in 7 Common utility modules supporting on-demand sub-path imports
|
|
22
22
|
- **Type Safe** - Complete TypeScript type definitions with configuration validators
|
|
23
23
|
- **On-demand Import** - Supports sub-path exports to reduce bundle size
|
|
24
24
|
|
|
@@ -149,6 +149,9 @@ import { ANSI } from '@meng-xi/vite-plugin/common/ui'
|
|
|
149
149
|
|
|
150
150
|
// Validation: chain validator, common validation functions
|
|
151
151
|
import { Validator, validateGlobalName, validateNoScriptInTemplate } from '@meng-xi/vite-plugin/common/validation'
|
|
152
|
+
|
|
153
|
+
// Path: path normalization, extension filtering, path exclusion matching, pre-compression detection
|
|
154
|
+
import { normalizePath, isExtensionIncluded, isPathExcluded, isPreCompressed } from '@meng-xi/vite-plugin/common/path'
|
|
152
155
|
```
|
|
153
156
|
|
|
154
157
|
| Sub-path | Description |
|
|
@@ -159,6 +162,7 @@ import { Validator, validateGlobalName, validateNoScriptInTemplate } from '@meng
|
|
|
159
162
|
| [`common/script`](https://mengxi-studio.github.io/vite-plugin/en/common/script.html) | Callback body wrapping into safe function expressions (with try-catch) |
|
|
160
163
|
| [`common/ui`](https://mengxi-studio.github.io/vite-plugin/en/common/ui.html) | Terminal ANSI color code constants |
|
|
161
164
|
| [`common/validation`](https://mengxi-studio.github.io/vite-plugin/en/common/validation.html) | Chain-style config validator, global name validation, script detection, callback field validation |
|
|
165
|
+
| [`common/path`](https://mengxi-studio.github.io/vite-plugin/en/common/path.html) | Path normalization, extension filtering, path exclusion matching, pre-compression format detection |
|
|
162
166
|
|
|
163
167
|
## Sub-path Exports
|
|
164
168
|
|
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
- **开箱即用** - 12 个实用插件,覆盖自动导入、构建进度、产物分析与压缩、文件复制、环境变量校验、路由生成、版本管理、HTML 注入、图标管理、全局 Loading 等场景
|
|
19
19
|
- **插件开发框架** - 导出 BasePlugin、Logger、Validator 等核心组件,快速构建自定义 Vite 插件
|
|
20
|
-
- **通用工具库** - 内置
|
|
20
|
+
- **通用工具库** - 内置 7 大 Common 工具模块,支持按需子路径导入
|
|
21
21
|
- **类型安全** - 完整 TypeScript 类型定义与配置验证器
|
|
22
22
|
- **按需导入** - 支持子路径导出,减少打包体积
|
|
23
23
|
|
|
@@ -148,6 +148,9 @@ import { ANSI } from '@meng-xi/vite-plugin/common/ui'
|
|
|
148
148
|
|
|
149
149
|
// 参数验证:链式验证器、通用校验函数
|
|
150
150
|
import { Validator, validateGlobalName, validateNoScriptInTemplate } from '@meng-xi/vite-plugin/common/validation'
|
|
151
|
+
|
|
152
|
+
// 路径处理:路径规范化、扩展名过滤、路径排除匹配、预压缩检测
|
|
153
|
+
import { normalizePath, isExtensionIncluded, isPathExcluded, isPreCompressed } from '@meng-xi/vite-plugin/common/path'
|
|
151
154
|
```
|
|
152
155
|
|
|
153
156
|
| 子路径 | 描述 |
|
|
@@ -158,6 +161,7 @@ import { Validator, validateGlobalName, validateNoScriptInTemplate } from '@meng
|
|
|
158
161
|
| [`common/script`](https://mengxi-studio.github.io/vite-plugin/common/script.html) | 回调函数体包装为安全的函数表达式(含 try-catch) |
|
|
159
162
|
| [`common/ui`](https://mengxi-studio.github.io/vite-plugin/common/ui.html) | 终端 ANSI 颜色码常量 |
|
|
160
163
|
| [`common/validation`](https://mengxi-studio.github.io/vite-plugin/common/validation.html) | 链式配置验证器、全局名称校验、脚本检测、回调字段校验 |
|
|
164
|
+
| [`common/path`](https://mengxi-studio.github.io/vite-plugin/common/path.html) | 路径规范化、扩展名过滤、路径排除匹配、预压缩格式检测 |
|
|
161
165
|
|
|
162
166
|
## 子路径导出
|
|
163
167
|
|
package/dist/common/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const common_format_index=require("./format/index.cjs"),common_fs_index=require("./fs/index.cjs"),common_html_index=require("./html/index.cjs"),common_script_index=require("./script/index.cjs"),common_ui_index=require("./ui/index.cjs"),validator=require("../shared/vite-plugin.Bcg6RW2N.cjs"),common_validation_index=require("./validation/index.cjs"),security=require("../shared/vite-plugin.CcvHfrL8.cjs");require("fs"),require("path"),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.escapeHtmlAttr=security.escapeHtmlAttr,exports.sanitizeContent=security.sanitizeContent;
|
|
1
|
+
"use strict";const common_format_index=require("./format/index.cjs"),common_fs_index=require("./fs/index.cjs"),common_html_index=require("./html/index.cjs"),common_path_index=require("./path/index.cjs"),common_script_index=require("./script/index.cjs"),common_ui_index=require("./ui/index.cjs"),validator=require("../shared/vite-plugin.Bcg6RW2N.cjs"),common_validation_index=require("./validation/index.cjs"),security=require("../shared/vite-plugin.CcvHfrL8.cjs");require("fs"),require("path"),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.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.escapeHtmlAttr=security.escapeHtmlAttr,exports.sanitizeContent=security.sanitizeContent;
|
package/dist/common/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { DateFormatOptions, formatDate, formatFileSize, getDateFormatParams, parseTemplate } from './format/index.cjs';
|
|
2
2
|
export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport } from './fs/index.cjs';
|
|
3
3
|
export { SanitizeRuleOptions, escapeHtmlAttr, injectBeforeTag, injectHeadAndBody, sanitizeContent } from './html/index.cjs';
|
|
4
|
+
export { isExtensionIncluded, isPathExcluded, isPreCompressed, normalizePath } from './path/index.cjs';
|
|
4
5
|
export { makeCallback } from './script/index.cjs';
|
|
5
6
|
export { ANSI } from './ui/index.cjs';
|
|
6
7
|
export { V as Validator } from '../shared/vite-plugin.DRRlWY8P.cjs';
|
package/dist/common/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { DateFormatOptions, formatDate, formatFileSize, getDateFormatParams, parseTemplate } from './format/index.mjs';
|
|
2
2
|
export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport } from './fs/index.mjs';
|
|
3
3
|
export { SanitizeRuleOptions, escapeHtmlAttr, injectBeforeTag, injectHeadAndBody, sanitizeContent } from './html/index.mjs';
|
|
4
|
+
export { isExtensionIncluded, isPathExcluded, isPreCompressed, normalizePath } from './path/index.mjs';
|
|
4
5
|
export { makeCallback } from './script/index.mjs';
|
|
5
6
|
export { ANSI } from './ui/index.mjs';
|
|
6
7
|
export { V as Validator } from '../shared/vite-plugin.DRRlWY8P.mjs';
|
package/dist/common/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { DateFormatOptions, formatDate, formatFileSize, getDateFormatParams, parseTemplate } from './format/index.js';
|
|
2
2
|
export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport } from './fs/index.js';
|
|
3
3
|
export { SanitizeRuleOptions, escapeHtmlAttr, injectBeforeTag, injectHeadAndBody, sanitizeContent } from './html/index.js';
|
|
4
|
+
export { isExtensionIncluded, isPathExcluded, isPreCompressed, normalizePath } from './path/index.js';
|
|
4
5
|
export { makeCallback } from './script/index.js';
|
|
5
6
|
export { ANSI } from './ui/index.js';
|
|
6
7
|
export { V as Validator } from '../shared/vite-plugin.DRRlWY8P.js';
|
package/dist/common/index.mjs
CHANGED
|
@@ -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{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{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:
|
|
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_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_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.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.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.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,14 @@
|
|
|
1
1
|
export { DateFormatOptions, formatDate, formatFileSize, getDateFormatParams, parseTemplate } from './common/format/index.cjs';
|
|
2
2
|
export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport } from './common/fs/index.cjs';
|
|
3
3
|
export { SanitizeRuleOptions, escapeHtmlAttr, injectBeforeTag, injectHeadAndBody, sanitizeContent } from './common/html/index.cjs';
|
|
4
|
+
export { isExtensionIncluded, isPathExcluded, isPreCompressed, normalizePath } from './common/path/index.cjs';
|
|
4
5
|
export { makeCallback } from './common/script/index.cjs';
|
|
5
6
|
export { ANSI } from './common/ui/index.cjs';
|
|
6
7
|
export { V as Validator } from './shared/vite-plugin.DRRlWY8P.cjs';
|
|
7
8
|
export { validateCallbackFields, validateGlobalName, validateNoScriptInTemplate } from './common/validation/index.cjs';
|
|
8
9
|
export { BasePlugin, BasePluginOptions, OptionsNormalizer, PluginFactory, PluginWithInstance, createPluginFactory } from './factory/index.cjs';
|
|
9
10
|
export { Logger } from './logger/index.cjs';
|
|
11
|
+
export { AssetGroup, AssetManifestOptions, AssetManifestResult, AssetMap, CustomFormatter, ManifestOutputFormat, WebpackEntryAsset, WebpackManifestOutput, assetManifest } from './plugins/assetManifest/index.cjs';
|
|
10
12
|
export { AutoImportOptions, ImportMapping, ResolvedImport, ScannedModule, TransformResult, autoImport } from './plugins/autoImport/index.cjs';
|
|
11
13
|
export { BuildPhase, BuildProgressOptions, ProgressFormat, ProgressTheme, buildProgress } from './plugins/buildProgress/index.cjs';
|
|
12
14
|
export { BundleAnalysisResult, BundleAnalyzerOptions, BundleOutputFormat, ChunkStats, ComparisonDiff, FileTypeDistribution, ModuleStats, SizeWarning, bundleAnalyzer } from './plugins/bundleAnalyzer/index.cjs';
|
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
export { DateFormatOptions, formatDate, formatFileSize, getDateFormatParams, parseTemplate } from './common/format/index.mjs';
|
|
2
2
|
export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport } from './common/fs/index.mjs';
|
|
3
3
|
export { SanitizeRuleOptions, escapeHtmlAttr, injectBeforeTag, injectHeadAndBody, sanitizeContent } from './common/html/index.mjs';
|
|
4
|
+
export { isExtensionIncluded, isPathExcluded, isPreCompressed, normalizePath } from './common/path/index.mjs';
|
|
4
5
|
export { makeCallback } from './common/script/index.mjs';
|
|
5
6
|
export { ANSI } from './common/ui/index.mjs';
|
|
6
7
|
export { V as Validator } from './shared/vite-plugin.DRRlWY8P.mjs';
|
|
7
8
|
export { validateCallbackFields, validateGlobalName, validateNoScriptInTemplate } from './common/validation/index.mjs';
|
|
8
9
|
export { BasePlugin, BasePluginOptions, OptionsNormalizer, PluginFactory, PluginWithInstance, createPluginFactory } from './factory/index.mjs';
|
|
9
10
|
export { Logger } from './logger/index.mjs';
|
|
11
|
+
export { AssetGroup, AssetManifestOptions, AssetManifestResult, AssetMap, CustomFormatter, ManifestOutputFormat, WebpackEntryAsset, WebpackManifestOutput, assetManifest } from './plugins/assetManifest/index.mjs';
|
|
10
12
|
export { AutoImportOptions, ImportMapping, ResolvedImport, ScannedModule, TransformResult, autoImport } from './plugins/autoImport/index.mjs';
|
|
11
13
|
export { BuildPhase, BuildProgressOptions, ProgressFormat, ProgressTheme, buildProgress } from './plugins/buildProgress/index.mjs';
|
|
12
14
|
export { BundleAnalysisResult, BundleAnalyzerOptions, BundleOutputFormat, ChunkStats, ComparisonDiff, FileTypeDistribution, ModuleStats, SizeWarning, bundleAnalyzer } from './plugins/bundleAnalyzer/index.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
export { DateFormatOptions, formatDate, formatFileSize, getDateFormatParams, parseTemplate } from './common/format/index.js';
|
|
2
2
|
export { CopyOptions, CopyResult, ScanDirectoryOptions, ScannedFile, checkSourceExists, copySourceToTarget, scanDirectory, shouldUpdateFileContent, writeFileContent, writeFileSyncSafely, writeJsonReport } from './common/fs/index.js';
|
|
3
3
|
export { SanitizeRuleOptions, escapeHtmlAttr, injectBeforeTag, injectHeadAndBody, sanitizeContent } from './common/html/index.js';
|
|
4
|
+
export { isExtensionIncluded, isPathExcluded, isPreCompressed, normalizePath } from './common/path/index.js';
|
|
4
5
|
export { makeCallback } from './common/script/index.js';
|
|
5
6
|
export { ANSI } from './common/ui/index.js';
|
|
6
7
|
export { V as Validator } from './shared/vite-plugin.DRRlWY8P.js';
|
|
7
8
|
export { validateCallbackFields, validateGlobalName, validateNoScriptInTemplate } from './common/validation/index.js';
|
|
8
9
|
export { BasePlugin, BasePluginOptions, OptionsNormalizer, PluginFactory, PluginWithInstance, createPluginFactory } from './factory/index.js';
|
|
9
10
|
export { Logger } from './logger/index.js';
|
|
11
|
+
export { AssetGroup, AssetManifestOptions, AssetManifestResult, AssetMap, CustomFormatter, ManifestOutputFormat, WebpackEntryAsset, WebpackManifestOutput, assetManifest } from './plugins/assetManifest/index.js';
|
|
10
12
|
export { AutoImportOptions, ImportMapping, ResolvedImport, ScannedModule, TransformResult, autoImport } from './plugins/autoImport/index.js';
|
|
11
13
|
export { BuildPhase, BuildProgressOptions, ProgressFormat, ProgressTheme, buildProgress } from './plugins/buildProgress/index.js';
|
|
12
14
|
export { BundleAnalysisResult, BundleAnalyzerOptions, BundleOutputFormat, ChunkStats, ComparisonDiff, FileTypeDistribution, ModuleStats, SizeWarning, bundleAnalyzer } from './plugins/bundleAnalyzer/index.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:
|
|
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{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{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("../../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;
|