vite-plugin-zip-file 2.1.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -6
- package/lib/index.cjs +1 -1
- package/lib/index.mjs +34 -28
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
Zip files at build time.
|
|
7
7
|
|
|
8
|
+
**Tips: Node.js 16+ is required.**
|
|
9
|
+
|
|
8
10
|
# Install
|
|
9
11
|
|
|
10
12
|
```
|
|
@@ -20,12 +22,28 @@ npm install vite-plugin-zip-file --save-dev
|
|
|
20
22
|
# Options
|
|
21
23
|
|
|
22
24
|
|
|
23
|
-
|
|
|
24
|
-
|
|
|
25
|
-
| folderPath
|
|
26
|
-
| outPath
|
|
27
|
-
| zipName
|
|
28
|
-
| enabled
|
|
25
|
+
| Params | Types | Rquired | Default | Desc |
|
|
26
|
+
| :----------- | ------------ | ------- | ------- | ------------------------------------------------------------ |
|
|
27
|
+
| folderPath | String\|Path | true | /dist | Path to the compressed folder |
|
|
28
|
+
| outPath | String\|Path | true | / | Compressed package output path |
|
|
29
|
+
| zipName | String | false | dist | Package name |
|
|
30
|
+
| enabled | Boolean | false | true | This parameter is used to control whether the plugin is enabled. It is usually used to determine whether to compress files according to the environment |
|
|
31
|
+
| deleteFolder | Boolean | false | false | Whether to delete source files after compression is completed |
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# Options(中文)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|
|
38
|
+
| :----------- | ------------ | ---- | ------ | ------------------------------------------------------- |
|
|
39
|
+
| folderPath | String\|Path | 是 | /dist | 需要被压缩的源文件夹 |
|
|
40
|
+
| outPath | String\|Path | 是 | / | 压缩包输出路径 |
|
|
41
|
+
| zipName | String | 否 | dist | 压缩包名称 |
|
|
42
|
+
| enabled | Boolean | 否 | true | 用于控制插件是否启用, 通常用于根据环境判断是否压缩文件 |
|
|
43
|
+
| deleteFolder | Boolean | 否 | false | 压缩完成后是否删除源文件 |
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
29
47
|
|
|
30
48
|
|
|
31
49
|
|
package/lib/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("path"),n=require("fs"),w=require("node:module");var h=typeof document<"u"?document.currentScript:null;const Z=w.createRequire(typeof document>"u"?require("url").pathToFileURL(__filename).href:h&&h.src||new URL("index.cjs",document.baseURI).href),r=t.sep,{cwd:v}=process,z={enabled:!0,folderPath:t.join(v(),"/dist"),outPath:t.resolve(v()),zipName:"",deleteFolder:!1},E=g=>{let b={...z,...g},{enabled:u,folderPath:c,outPath:s,zipName:o,deleteFolder:j}=b;if(u=!!u,!c||!s)throw new Error("config.folderPath and config.outPath is required.");c=t.resolve(c),s=t.resolve(s),o=o||c.split(r).pop()+".zip";const q=()=>{const F=Z("jszip"),p=new F,a=function(e,i,l=""){const d=n.readdirSync(i);l+=i.split(r).pop()+r,d.forEach(S=>{const f=t.join(i,r,S);n.statSync(f).isDirectory()?a(e,f,l):e.file(l+S,n.readFileSync(f))})},y=(e=o)=>{const i=t.join(s,r+e);n.existsSync(i)&&n.unlinkSync(i)},m=e=>{n.readdirSync(e).forEach(l=>{const d=e+r+l;n.statSync(d).isDirectory()?m(d):n.unlinkSync(d)}),n.rmdirSync(e)},P=function(){a(p,c),p.generateAsync({type:"nodebuffer",compression:"DEFLATE",compressionOptions:{level:9}}).then(e=>{y(o),n.writeFileSync(t.join(s,r,o),e),j&&m(c)})};y(o),P()};return{name:"vite-plugin-zip-file",apply:"build",closeBundle(){u&&q()}}};exports.viteZip=E;
|
package/lib/index.mjs
CHANGED
|
@@ -1,31 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import t from "path";
|
|
2
|
+
import o from "fs";
|
|
3
3
|
import { createRequire as z } from "node:module";
|
|
4
|
-
const
|
|
4
|
+
const E = z(import.meta.url), r = t.sep, { cwd: h } = process, Z = {
|
|
5
5
|
enabled: !0,
|
|
6
|
-
folderPath:
|
|
7
|
-
outPath:
|
|
8
|
-
zipName: ""
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
folderPath: t.join(h(), "/dist"),
|
|
7
|
+
outPath: t.resolve(h()),
|
|
8
|
+
zipName: "",
|
|
9
|
+
deleteFolder: !1
|
|
10
|
+
}, A = (v) => {
|
|
11
|
+
let g = {
|
|
11
12
|
...Z,
|
|
12
|
-
...
|
|
13
|
-
}, { enabled:
|
|
14
|
-
if (
|
|
13
|
+
...v
|
|
14
|
+
}, { enabled: f, folderPath: s, outPath: c, zipName: n, deleteFolder: F } = g;
|
|
15
|
+
if (f = !!f, !s || !c)
|
|
15
16
|
throw new Error("config.folderPath and config.outPath is required.");
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
l +=
|
|
21
|
-
const a =
|
|
22
|
-
|
|
17
|
+
s = t.resolve(s), c = t.resolve(c), n = n || s.split(r).pop() + ".zip";
|
|
18
|
+
const P = () => {
|
|
19
|
+
const j = E("jszip"), d = new j(), u = function(e, i, l = "") {
|
|
20
|
+
const p = o.readdirSync(i);
|
|
21
|
+
l += i.split(r).pop() + r, p.forEach((S) => {
|
|
22
|
+
const a = t.join(i, r, S);
|
|
23
|
+
o.statSync(a).isDirectory() ? u(e, a, l) : e.file(l + S, o.readFileSync(a));
|
|
23
24
|
});
|
|
24
|
-
},
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
|
|
25
|
+
}, m = (e = n) => {
|
|
26
|
+
const i = t.join(c, r + e);
|
|
27
|
+
o.existsSync(i) && o.unlinkSync(i);
|
|
28
|
+
}, y = (e) => {
|
|
29
|
+
o.readdirSync(e).forEach((l) => {
|
|
30
|
+
const p = e + r + l;
|
|
31
|
+
o.statSync(p).isDirectory() ? y(p) : o.unlinkSync(p);
|
|
32
|
+
}), o.rmdirSync(e);
|
|
33
|
+
}, w = function() {
|
|
34
|
+
u(d, s), d.generateAsync({
|
|
29
35
|
type: "nodebuffer",
|
|
30
36
|
// 压缩类型
|
|
31
37
|
compression: "DEFLATE",
|
|
@@ -34,20 +40,20 @@ const P = z(import.meta.url), s = e.sep, { cwd: h } = process, Z = {
|
|
|
34
40
|
// 压缩级别
|
|
35
41
|
level: 9
|
|
36
42
|
}
|
|
37
|
-
}).then((
|
|
38
|
-
|
|
43
|
+
}).then((e) => {
|
|
44
|
+
m(n), o.writeFileSync(t.join(c, r, n), e), F && y(s);
|
|
39
45
|
});
|
|
40
46
|
};
|
|
41
|
-
|
|
47
|
+
m(n), w();
|
|
42
48
|
};
|
|
43
49
|
return {
|
|
44
50
|
name: "vite-plugin-zip-file",
|
|
45
51
|
apply: "build",
|
|
46
52
|
closeBundle() {
|
|
47
|
-
|
|
53
|
+
f && P();
|
|
48
54
|
}
|
|
49
55
|
};
|
|
50
56
|
};
|
|
51
57
|
export {
|
|
52
|
-
|
|
58
|
+
A as viteZip
|
|
53
59
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-zip-file",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "zip files at build time.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.cjs",
|
|
@@ -36,7 +36,10 @@
|
|
|
36
36
|
"jszip": "^3.10.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"vite": "^
|
|
40
|
-
"@rollup/plugin-node-resolve": "^
|
|
39
|
+
"vite": "^5.1.0",
|
|
40
|
+
"@rollup/plugin-node-resolve": "^15.2.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"vite": ">=2.0.0"
|
|
41
44
|
}
|
|
42
45
|
}
|