coda-builder 1.2.4 → 1.2.6
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/build/index.d.mts +4 -2
- package/build/index.d.ts +4 -2
- package/build/index.js +10 -5
- package/build/index.mjs +10 -5
- package/package.json +3 -16
package/build/index.d.mts
CHANGED
|
@@ -23,13 +23,15 @@ type TechRoute = 'sdk' | 'react' | 'vue' | 'node-cli' | 'node-server' | 'chrome-
|
|
|
23
23
|
*/
|
|
24
24
|
type BuildMode = 'production' | 'development' | 'analyzer';
|
|
25
25
|
/** 单文件复制规则 */
|
|
26
|
-
|
|
26
|
+
interface CopySingleRule {
|
|
27
27
|
type: 'single';
|
|
28
28
|
/** 源文件路径 */
|
|
29
29
|
from: string;
|
|
30
30
|
/** 目标输出路径 */
|
|
31
31
|
to: string;
|
|
32
|
-
|
|
32
|
+
/** 可选:对单文件内容进行自定义转换修改 */
|
|
33
|
+
transform?: (content: Buffer) => Buffer | string;
|
|
34
|
+
}
|
|
33
35
|
/** 目录递归复制规则 */
|
|
34
36
|
type CopyDirectoryRule = {
|
|
35
37
|
type: 'directory';
|
package/build/index.d.ts
CHANGED
|
@@ -23,13 +23,15 @@ type TechRoute = 'sdk' | 'react' | 'vue' | 'node-cli' | 'node-server' | 'chrome-
|
|
|
23
23
|
*/
|
|
24
24
|
type BuildMode = 'production' | 'development' | 'analyzer';
|
|
25
25
|
/** 单文件复制规则 */
|
|
26
|
-
|
|
26
|
+
interface CopySingleRule {
|
|
27
27
|
type: 'single';
|
|
28
28
|
/** 源文件路径 */
|
|
29
29
|
from: string;
|
|
30
30
|
/** 目标输出路径 */
|
|
31
31
|
to: string;
|
|
32
|
-
|
|
32
|
+
/** 可选:对单文件内容进行自定义转换修改 */
|
|
33
|
+
transform?: (content: Buffer) => Buffer | string;
|
|
34
|
+
}
|
|
33
35
|
/** 目录递归复制规则 */
|
|
34
36
|
type CopyDirectoryRule = {
|
|
35
37
|
type: 'directory';
|
package/build/index.js
CHANGED
|
@@ -538,7 +538,7 @@ var CodaCopyWebpackPlugin = class {
|
|
|
538
538
|
this.rules.forEach((rule) => {
|
|
539
539
|
if (!import_fs.default.existsSync(rule.from)) return;
|
|
540
540
|
if (rule.type === "single") {
|
|
541
|
-
this.processSingleFile(compilation, rule.from, rule.to);
|
|
541
|
+
this.processSingleFile(compilation, rule.from, rule.to, rule.transform);
|
|
542
542
|
} else if (rule.type === "directory") {
|
|
543
543
|
this.processDirectory(compilation, rule.from, rule.to, rule.ignore || []);
|
|
544
544
|
} else if (rule.type === "template") {
|
|
@@ -550,15 +550,20 @@ var CodaCopyWebpackPlugin = class {
|
|
|
550
550
|
});
|
|
551
551
|
}
|
|
552
552
|
/**
|
|
553
|
-
*
|
|
553
|
+
* 处理单文件复制规则(支持自定义内容转换)
|
|
554
554
|
* @private
|
|
555
555
|
* @param {Compilation} compilation Webpack 编译对象
|
|
556
556
|
* @param {string} from 源文件绝对路径
|
|
557
557
|
* @param {string} to 目标输出相对路径
|
|
558
|
+
* @param {(content: Buffer) => Buffer | string} [transform] 内容转换函数
|
|
558
559
|
*/
|
|
559
|
-
processSingleFile(compilation, from, to) {
|
|
560
|
-
|
|
561
|
-
|
|
560
|
+
processSingleFile(compilation, from, to, transform) {
|
|
561
|
+
let content = import_fs.default.readFileSync(from);
|
|
562
|
+
if (typeof transform === "function") {
|
|
563
|
+
content = transform(content);
|
|
564
|
+
}
|
|
565
|
+
const finalBuffer = Buffer.isBuffer(content) ? content : Buffer.from(content);
|
|
566
|
+
compilation.emitAsset(to, new compilation.compiler.webpack.sources.RawSource(finalBuffer));
|
|
562
567
|
}
|
|
563
568
|
/**
|
|
564
569
|
* 处理目录递归复制规则
|
package/build/index.mjs
CHANGED
|
@@ -509,7 +509,7 @@ var CodaCopyWebpackPlugin = class {
|
|
|
509
509
|
this.rules.forEach((rule) => {
|
|
510
510
|
if (!fs.existsSync(rule.from)) return;
|
|
511
511
|
if (rule.type === "single") {
|
|
512
|
-
this.processSingleFile(compilation, rule.from, rule.to);
|
|
512
|
+
this.processSingleFile(compilation, rule.from, rule.to, rule.transform);
|
|
513
513
|
} else if (rule.type === "directory") {
|
|
514
514
|
this.processDirectory(compilation, rule.from, rule.to, rule.ignore || []);
|
|
515
515
|
} else if (rule.type === "template") {
|
|
@@ -521,15 +521,20 @@ var CodaCopyWebpackPlugin = class {
|
|
|
521
521
|
});
|
|
522
522
|
}
|
|
523
523
|
/**
|
|
524
|
-
*
|
|
524
|
+
* 处理单文件复制规则(支持自定义内容转换)
|
|
525
525
|
* @private
|
|
526
526
|
* @param {Compilation} compilation Webpack 编译对象
|
|
527
527
|
* @param {string} from 源文件绝对路径
|
|
528
528
|
* @param {string} to 目标输出相对路径
|
|
529
|
+
* @param {(content: Buffer) => Buffer | string} [transform] 内容转换函数
|
|
529
530
|
*/
|
|
530
|
-
processSingleFile(compilation, from, to) {
|
|
531
|
-
|
|
532
|
-
|
|
531
|
+
processSingleFile(compilation, from, to, transform) {
|
|
532
|
+
let content = fs.readFileSync(from);
|
|
533
|
+
if (typeof transform === "function") {
|
|
534
|
+
content = transform(content);
|
|
535
|
+
}
|
|
536
|
+
const finalBuffer = Buffer.isBuffer(content) ? content : Buffer.from(content);
|
|
537
|
+
compilation.emitAsset(to, new compilation.compiler.webpack.sources.RawSource(finalBuffer));
|
|
533
538
|
}
|
|
534
539
|
/**
|
|
535
540
|
* 处理目录递归复制规则
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "coda-builder",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"description": "coda-builder是一款基于 TypeScript + Webpack 的企业级构建工具,旨在统一管理多平台项目(WEB、Node、Chrome扩展程序、VS Code扩展程序等),使开发人员享受开箱即用的体验。",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -12,21 +12,8 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"publishConfig": {
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"exports": {
|
|
18
|
-
".": {
|
|
19
|
-
"types": "./build/index.d.ts",
|
|
20
|
-
"import": {
|
|
21
|
-
"types": "./build/index.d.mts",
|
|
22
|
-
"default": "./build/index.mjs"
|
|
23
|
-
},
|
|
24
|
-
"require": {
|
|
25
|
-
"types": "./build/index.d.ts",
|
|
26
|
-
"default": "./build/index.js"
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
15
|
+
"directory": "dist",
|
|
16
|
+
"access": "public"
|
|
30
17
|
},
|
|
31
18
|
"engines": {
|
|
32
19
|
"node": ">=22.0.0"
|