vite-plugin-zip-file 1.1.0 → 2.1.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 +6 -3
- package/lib/index.cjs +1 -1
- package/lib/index.mjs +32 -29
- package/package.json +3 -6
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# vite-plugin-zip-file
|
|
2
2
|
[](./LICENSE)
|
|
3
|
+

|
|
3
4
|
[](https://www.npmjs.com/package/vite-plugin-zip-file)
|
|
4
5
|
|
|
5
6
|
Zip files at build time.
|
|
@@ -21,10 +22,12 @@ npm install vite-plugin-zip-file --save-dev
|
|
|
21
22
|
|
|
22
23
|
| Param | Types | Rquired | Default | Desc |
|
|
23
24
|
| :--------- | ------------ | ------- | ------- | ------------------------------------------------------------ |
|
|
24
|
-
| folderPath | String\|Path | true |
|
|
25
|
-
| outPath | String\|Path | true |
|
|
25
|
+
| folderPath | String\|Path | true | /dist | Path to the compressed folder |
|
|
26
|
+
| outPath | String\|Path | true | / | Compressed package output path |
|
|
26
27
|
| zipName | String | false | dist | Package name |
|
|
27
|
-
| enabled
|
|
28
|
+
| 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 |
|
|
29
|
+
|
|
30
|
+
|
|
28
31
|
|
|
29
32
|
|
|
30
33
|
|
package/lib/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("path"),i=require("fs"),q=require("node:module"),w=q.createRequire(typeof document>"u"?new(require("url")).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("index.cjs",document.baseURI).href),r=e.sep,{cwd:y}=process,P={enabled:!0,folderPath:e.join(y(),"/dist"),outPath:e.resolve(y()),zipName:""},Z=h=>{let S={...P,...h},{enabled:l,folderPath:c,outPath:s,zipName:n}=S;if(l=Boolean(l),!c||!s)throw new Error("config.folderPath and config.outPath is required.");c=e.resolve(c),s=e.resolve(s),n=n||c.split(r).pop()+".zip";const v=()=>{const g=w("jszip"),d=new g,f=function(t,o,p=""){const j=i.readdirSync(o);p+=o.split(r).pop()+r,j.forEach(m=>{const u=e.join(o,r,m);i.statSync(u).isDirectory()?f(t,u,p):t.file(p+m,i.readFileSync(u))})},a=(t=n)=>{const o=e.join(s,r+t);i.existsSync(o)&&i.unlinkSync(o)},b=function(){f(d,c),d.generateAsync({type:"nodebuffer",compression:"DEFLATE",compressionOptions:{level:9}}).then(t=>{a(n),i.writeFileSync(e.join(s,r,n),t)})};a(n),b()};return{name:"vite-plugin-zip-file",apply:"build",closeBundle(){l&&v()}}};exports.viteZip=Z;
|
package/lib/index.mjs
CHANGED
|
@@ -1,50 +1,53 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { createRequire as
|
|
4
|
-
const
|
|
1
|
+
import e from "path";
|
|
2
|
+
import i from "fs";
|
|
3
|
+
import { createRequire as z } from "node:module";
|
|
4
|
+
const P = z(import.meta.url), s = e.sep, { cwd: h } = process, Z = {
|
|
5
5
|
enabled: !0,
|
|
6
|
-
folderPath: "",
|
|
7
|
-
outPath:
|
|
6
|
+
folderPath: e.join(h(), "/dist"),
|
|
7
|
+
outPath: e.resolve(h()),
|
|
8
8
|
zipName: ""
|
|
9
|
-
},
|
|
10
|
-
let
|
|
11
|
-
...
|
|
12
|
-
...
|
|
13
|
-
}, { enabled: p, folderPath:
|
|
14
|
-
if (p = Boolean(p), !
|
|
9
|
+
}, k = (y) => {
|
|
10
|
+
let S = {
|
|
11
|
+
...Z,
|
|
12
|
+
...y
|
|
13
|
+
}, { enabled: p, folderPath: r, outPath: c, zipName: o } = S;
|
|
14
|
+
if (p = Boolean(p), !r || !c)
|
|
15
15
|
throw new Error("config.folderPath and config.outPath is required.");
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const g =
|
|
19
|
-
const
|
|
20
|
-
l +=
|
|
21
|
-
const a =
|
|
22
|
-
|
|
16
|
+
r = e.resolve(r), c = e.resolve(c), o = o || r.split(s).pop() + ".zip";
|
|
17
|
+
const v = () => {
|
|
18
|
+
const g = P("jszip"), f = new g(), d = function(t, n, l = "") {
|
|
19
|
+
const w = i.readdirSync(n);
|
|
20
|
+
l += n.split(s).pop() + s, w.forEach((m) => {
|
|
21
|
+
const a = e.join(n, s, m);
|
|
22
|
+
i.statSync(a).isDirectory() ? d(t, a, l) : t.file(l + m, i.readFileSync(a));
|
|
23
23
|
});
|
|
24
|
-
},
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
|
|
24
|
+
}, u = (t = o) => {
|
|
25
|
+
const n = e.join(c, s + t);
|
|
26
|
+
i.existsSync(n) && i.unlinkSync(n);
|
|
27
|
+
}, j = function() {
|
|
28
|
+
d(f, r), f.generateAsync({
|
|
29
29
|
type: "nodebuffer",
|
|
30
|
+
// 压缩类型
|
|
30
31
|
compression: "DEFLATE",
|
|
32
|
+
// 压缩算法
|
|
31
33
|
compressionOptions: {
|
|
34
|
+
// 压缩级别
|
|
32
35
|
level: 9
|
|
33
36
|
}
|
|
34
|
-
}).then((
|
|
35
|
-
|
|
37
|
+
}).then((t) => {
|
|
38
|
+
u(o), i.writeFileSync(e.join(c, s, o), t);
|
|
36
39
|
});
|
|
37
40
|
};
|
|
38
|
-
|
|
41
|
+
u(o), j();
|
|
39
42
|
};
|
|
40
43
|
return {
|
|
41
44
|
name: "vite-plugin-zip-file",
|
|
42
45
|
apply: "build",
|
|
43
46
|
closeBundle() {
|
|
44
|
-
|
|
47
|
+
p && v();
|
|
45
48
|
}
|
|
46
49
|
};
|
|
47
50
|
};
|
|
48
51
|
export {
|
|
49
|
-
|
|
52
|
+
k as viteZip
|
|
50
53
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-zip-file",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "zip files at build time.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.cjs",
|
|
@@ -32,14 +32,11 @@
|
|
|
32
32
|
"url": "https://github.com/Ssis53/vite-plugin-zip/issues"
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://github.com/Ssis53/vite-plugin-zip#readme",
|
|
35
|
-
"peerDependencies": {
|
|
36
|
-
"vite": "^3.0.7"
|
|
37
|
-
},
|
|
38
35
|
"dependencies": {
|
|
39
|
-
"jszip": "^3.10.1"
|
|
40
|
-
"vite-plugin-zip-file": "^1.0.3"
|
|
36
|
+
"jszip": "^3.10.1"
|
|
41
37
|
},
|
|
42
38
|
"devDependencies": {
|
|
39
|
+
"vite": "^4.0.4",
|
|
43
40
|
"@rollup/plugin-node-resolve": "^13.3.0"
|
|
44
41
|
}
|
|
45
42
|
}
|