@divriots/jampack 0.9.4 → 0.10.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 +1 -0
- package/dist/compressors/images.d.ts +1 -1
- package/dist/compressors/images.js +16 -14
- package/dist/config-default.d.ts +3 -0
- package/dist/config-default.js +31 -0
- package/dist/config-fast.d.ts +2 -0
- package/dist/config-fast.js +26 -0
- package/dist/config-types.d.ts +27 -0
- package/dist/config-types.js +1 -0
- package/dist/config.d.ts +3 -29
- package/dist/config.js +16 -57
- package/dist/index.js +4 -2
- package/package.json +17 -15
package/README.md
CHANGED
|
@@ -68,6 +68,7 @@ For more options see [CLI options](https://jampack.divriots.com/cli-options).
|
|
|
68
68
|
- [bayjs.org](https://bayjs.org/)
|
|
69
69
|
- [qwind.pages.dev](https://qwind.pages.dev/)
|
|
70
70
|
- [Bloycey's Blog](https://bloycey.blog/)
|
|
71
|
+
- [codenanshu.in](https://codenanshu.in/)
|
|
71
72
|
|
|
72
73
|
> Add yours here
|
|
73
74
|
|
|
@@ -3,7 +3,7 @@ import sharp from 'sharp';
|
|
|
3
3
|
import { MimeType } from 'file-type';
|
|
4
4
|
export type ImageMimeType = MimeType | 'image/svg+xml';
|
|
5
5
|
export declare const AllImageFormat: string[];
|
|
6
|
-
export type ImageFormat = typeof AllImageFormat[number] | undefined;
|
|
6
|
+
export type ImageFormat = (typeof AllImageFormat)[number] | undefined;
|
|
7
7
|
export type Image = {
|
|
8
8
|
format: ImageFormat;
|
|
9
9
|
data: Buffer;
|
|
@@ -30,24 +30,26 @@ export async function compressImage(data, options) {
|
|
|
30
30
|
let outputFormat;
|
|
31
31
|
// Special case for svg
|
|
32
32
|
if (meta.format === 'svg') {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
try {
|
|
34
|
+
const output = svgo(data.toString(), {
|
|
35
|
+
multipass: true,
|
|
36
|
+
plugins: [
|
|
37
|
+
{
|
|
38
|
+
name: 'preset-default',
|
|
39
|
+
params: {
|
|
40
|
+
overrides: {
|
|
41
|
+
removeViewBox: false,
|
|
42
|
+
},
|
|
41
43
|
},
|
|
42
44
|
},
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
],
|
|
46
|
+
});
|
|
47
|
+
return { format: 'svg', data: Buffer.from(output.data, 'utf8') };
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
// In case of any issue with svg compression:
|
|
48
51
|
return undefined;
|
|
49
52
|
}
|
|
50
|
-
return { format: 'svg', data: Buffer.from(newData.data, 'utf8') };
|
|
51
53
|
}
|
|
52
54
|
// TODO
|
|
53
55
|
// Use information of input image to the destination format
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const default_options = {
|
|
2
|
+
image: {
|
|
3
|
+
embed_size: 1500,
|
|
4
|
+
srcset_min_width: 640,
|
|
5
|
+
compress: true,
|
|
6
|
+
jpeg: {
|
|
7
|
+
options: {
|
|
8
|
+
quality: 75,
|
|
9
|
+
mozjpeg: true,
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
png: {
|
|
13
|
+
options: {
|
|
14
|
+
compressionLevel: 9,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
webp: {
|
|
18
|
+
options_lossless: {
|
|
19
|
+
effort: 4,
|
|
20
|
+
quality: 77,
|
|
21
|
+
mode: 'lossless',
|
|
22
|
+
},
|
|
23
|
+
options_lossly: {
|
|
24
|
+
effort: 4,
|
|
25
|
+
quality: 77,
|
|
26
|
+
mode: 'lossly',
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
export default default_options;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const fast_options_override = {
|
|
2
|
+
image: {
|
|
3
|
+
embed_size: 0,
|
|
4
|
+
srcset_min_width: 16000,
|
|
5
|
+
compress: false,
|
|
6
|
+
jpeg: {
|
|
7
|
+
options: {
|
|
8
|
+
mozjpeg: false,
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
png: {
|
|
12
|
+
options: {
|
|
13
|
+
compressionLevel: 0,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
webp: {
|
|
17
|
+
options_lossless: {
|
|
18
|
+
effort: 0,
|
|
19
|
+
},
|
|
20
|
+
options_lossly: {
|
|
21
|
+
effort: 0,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
export default fast_options_override;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type WebpOptions = {
|
|
2
|
+
effort: number;
|
|
3
|
+
mode: 'lossless' | 'lossly';
|
|
4
|
+
quality: number;
|
|
5
|
+
};
|
|
6
|
+
export type Options = {
|
|
7
|
+
image: {
|
|
8
|
+
embed_size: number;
|
|
9
|
+
srcset_min_width: number;
|
|
10
|
+
compress: boolean;
|
|
11
|
+
jpeg: {
|
|
12
|
+
options: {
|
|
13
|
+
quality: number;
|
|
14
|
+
mozjpeg: boolean;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
png: {
|
|
18
|
+
options: {
|
|
19
|
+
compressionLevel: number;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
webp: {
|
|
23
|
+
options_lossless: WebpOptions;
|
|
24
|
+
options_lossly: WebpOptions;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/config.d.ts
CHANGED
|
@@ -1,30 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
effort: number;
|
|
3
|
-
mode: 'lossless' | 'lossly';
|
|
4
|
-
quality: number;
|
|
5
|
-
};
|
|
6
|
-
export type Options = {
|
|
7
|
-
image: {
|
|
8
|
-
embed_size: number;
|
|
9
|
-
srcset_min_width: number;
|
|
10
|
-
compress: boolean;
|
|
11
|
-
jpeg: {
|
|
12
|
-
options: {
|
|
13
|
-
quality: number;
|
|
14
|
-
mozjpeg: boolean;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
png: {
|
|
18
|
-
options: {
|
|
19
|
-
compressionLevel: number;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
webp: {
|
|
23
|
-
options_lossless: WebpOptions;
|
|
24
|
-
options_lossly: WebpOptions;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
declare const default_options: Options;
|
|
1
|
+
declare const options: import("./config-types.js").Options;
|
|
29
2
|
export declare function fast(): void;
|
|
30
|
-
export
|
|
3
|
+
export declare function loadConfig(): Promise<void>;
|
|
4
|
+
export default options;
|
package/dist/config.js
CHANGED
|
@@ -1,59 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
options: {
|
|
8
|
-
quality: 75,
|
|
9
|
-
mozjpeg: true,
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
png: {
|
|
13
|
-
options: {
|
|
14
|
-
compressionLevel: 9,
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
webp: {
|
|
18
|
-
options_lossless: {
|
|
19
|
-
effort: 4,
|
|
20
|
-
quality: 77,
|
|
21
|
-
mode: 'lossless',
|
|
22
|
-
},
|
|
23
|
-
options_lossly: {
|
|
24
|
-
effort: 4,
|
|
25
|
-
quality: 77,
|
|
26
|
-
mode: 'lossly',
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
const fast_options_override = {
|
|
32
|
-
image: {
|
|
33
|
-
embed_size: 0,
|
|
34
|
-
srcset_min_width: 16000,
|
|
35
|
-
compress: false,
|
|
36
|
-
jpeg: {
|
|
37
|
-
options: {
|
|
38
|
-
mozjpeg: false,
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
png: {
|
|
42
|
-
options: {
|
|
43
|
-
compressionLevel: 0,
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
webp: {
|
|
47
|
-
options_lossless: {
|
|
48
|
-
effort: 0,
|
|
49
|
-
},
|
|
50
|
-
options_lossly: {
|
|
51
|
-
effort: 0,
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
};
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import load from '@proload/core';
|
|
3
|
+
import deepmerge from 'deepmerge';
|
|
4
|
+
import default_options from './config-default.js';
|
|
5
|
+
import fast_options_override from './config-fast.js';
|
|
6
|
+
const options = default_options;
|
|
56
7
|
export function fast() {
|
|
57
|
-
|
|
8
|
+
deepmerge(options, fast_options_override);
|
|
58
9
|
}
|
|
59
|
-
export
|
|
10
|
+
export async function loadConfig() {
|
|
11
|
+
const proload = await load('jampack', { mustExist: false });
|
|
12
|
+
if (proload) {
|
|
13
|
+
console.log('Overriding default config with:');
|
|
14
|
+
console.log(JSON.stringify(proload.value, null, 2));
|
|
15
|
+
deepmerge(options, proload.value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export default options;
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { optimize } from './optimize.js';
|
|
|
5
5
|
import $state from './state.js';
|
|
6
6
|
import { table } from 'table';
|
|
7
7
|
import { formatBytes } from './utils.js';
|
|
8
|
-
import { fast } from './config.js';
|
|
8
|
+
import { fast, loadConfig } from './config.js';
|
|
9
9
|
import { printTitle } from './logger.js';
|
|
10
10
|
import { exit } from 'process';
|
|
11
11
|
import kleur from 'kleur';
|
|
@@ -41,7 +41,9 @@ program
|
|
|
41
41
|
.action(async (dir, options) => {
|
|
42
42
|
$state.dir = dir;
|
|
43
43
|
$state.args = options;
|
|
44
|
-
// Override config with
|
|
44
|
+
// Override default config with config file
|
|
45
|
+
await loadConfig();
|
|
46
|
+
// Override config with fast options if set
|
|
45
47
|
if (options.fast) {
|
|
46
48
|
fast();
|
|
47
49
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@divriots/jampack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Packer for static websites",
|
|
5
5
|
"author": "Georges Gomes @georges-gomes",
|
|
6
6
|
"bin": {
|
|
@@ -16,33 +16,35 @@
|
|
|
16
16
|
"/dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@
|
|
19
|
+
"@proload/core": "^0.3.3",
|
|
20
|
+
"@swc/core": "^1.3.57",
|
|
20
21
|
"@types/cheerio": "^0.22.31",
|
|
21
22
|
"@types/csso": "^5.0.0",
|
|
22
23
|
"@types/html-minifier-terser": "^7.0.0",
|
|
23
|
-
"@types/sharp": "^0.
|
|
24
|
-
"@types/svgo": "^
|
|
24
|
+
"@types/sharp": "^0.32.0",
|
|
25
|
+
"@types/svgo": "^3.0.0",
|
|
25
26
|
"cheerio": "0.22.0",
|
|
26
|
-
"commander": "^
|
|
27
|
+
"commander": "^10.0.1",
|
|
27
28
|
"csso": "^5.0.5",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
29
|
+
"deepmerge": "^4.3.1",
|
|
30
|
+
"file-type": "^18.4.0",
|
|
31
|
+
"globby": "^13.1.4",
|
|
30
32
|
"hasha": "^5.2.2",
|
|
31
|
-
"html-minifier-terser": "^7.
|
|
33
|
+
"html-minifier-terser": "^7.2.0",
|
|
32
34
|
"kleur": "^4.1.5",
|
|
33
|
-
"lightningcss": "^1.
|
|
35
|
+
"lightningcss": "^1.20.0",
|
|
34
36
|
"mini-svg-data-uri": "^1.4.4",
|
|
35
|
-
"ora": "^6.
|
|
36
|
-
"sharp": "^0.
|
|
37
|
-
"svgo": "^
|
|
37
|
+
"ora": "^6.3.0",
|
|
38
|
+
"sharp": "^0.32.1",
|
|
39
|
+
"svgo": "^3.0.2",
|
|
38
40
|
"table": "^6.8.1"
|
|
39
41
|
},
|
|
40
42
|
"devDependencies": {
|
|
41
|
-
"@types/node": "^16.
|
|
43
|
+
"@types/node": "^16.18.28",
|
|
42
44
|
"shx": "^0.3.3",
|
|
43
45
|
"ts-node": "^10.2.1",
|
|
44
|
-
"tslib": "^2.
|
|
45
|
-
"typescript": "^
|
|
46
|
+
"tslib": "^2.5.0",
|
|
47
|
+
"typescript": "^5.0.4"
|
|
46
48
|
},
|
|
47
49
|
"scripts": {
|
|
48
50
|
"watch": "pnpm build --watch",
|