@divriots/jampack 0.1.6 → 0.1.8

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/dist/compress.js CHANGED
@@ -89,7 +89,18 @@ export const compressImage = async (data, resize) => {
89
89
  const meta = await sharpFile.metadata();
90
90
  switch (meta.format) {
91
91
  case 'svg':
92
- const newData = svgo(data, {});
92
+ const newData = svgo(data, {
93
+ multipass: true,
94
+ plugins: [{
95
+ name: "preset-default",
96
+ params: {
97
+ overrides: {
98
+ removeViewBox: false,
99
+ },
100
+ },
101
+ }
102
+ ],
103
+ });
93
104
  if (newData.error || newData.modernError) {
94
105
  console.log(`Error processing svg ${data}`);
95
106
  return undefined;
@@ -100,7 +111,11 @@ export const compressImage = async (data, resize) => {
100
111
  case 'jpeg':
101
112
  case 'webp':
102
113
  //case 'gif':
103
- return await sharpFile.resize({ ...resize, fit: 'fill', withoutEnlargement: true }).toBuffer();
114
+ let sf = sharpFile;
115
+ if (resize.width && resize.height) {
116
+ sf = sf.resize({ ...resize, fit: 'fill', withoutEnlargement: true });
117
+ }
118
+ return await sf.toBuffer();
104
119
  }
105
120
  return undefined;
106
121
  };
package/dist/optimize.js CHANGED
@@ -124,14 +124,6 @@ async function processImage(file, $, imgElement) {
124
124
  return;
125
125
  }
126
126
  /*
127
- * Attribute 'width' & 'height'
128
- */
129
- const [w, h] = setImageSize(img, meta);
130
- if (w < 0 || h < 0) {
131
- console.warn(`Unexpected error in image size calculation - some optimizations can't be done`);
132
- return;
133
- }
134
- /*
135
127
  * Compress image
136
128
  */
137
129
  if (!globalState.compressedFiles.has(absoluteImgPath)) {
@@ -141,7 +133,7 @@ async function processImage(file, $, imgElement) {
141
133
  originalSize: originalData.length,
142
134
  compressedSize: originalData.length
143
135
  };
144
- const newImage = await compressImage(originalData, { width: w, height: h });
136
+ const newImage = await compressImage(originalData, {});
145
137
  if (newImage && newImage.length < originalData.length) {
146
138
  if (!globalState.args.nowrite) {
147
139
  fs.writeFile(absoluteImgPath, newImage);
@@ -150,11 +142,27 @@ async function processImage(file, $, imgElement) {
150
142
  }
151
143
  globalState.addFile(result);
152
144
  }
145
+ //
146
+ // Stop here if svg
147
+ //
148
+ if (meta.format === 'svg')
149
+ return;
150
+ /*
151
+ * Attribute 'width' & 'height'
152
+ */
153
+ const [w, h] = setImageSize(img, meta);
154
+ if (w < 0 || h < 0) {
155
+ console.warn(`Unexpected error in image size calculation - some optimizations can't be done`);
156
+ return;
157
+ }
158
+ /*
159
+ * Attribute 'srcset'
160
+ */
153
161
  const attr_srcset = img.attr('srcset');
154
162
  if (attr_srcset) {
155
163
  // If srcset is set, don't touch it.
156
- // Just compress files
157
- // TODO
164
+ // The compress pass will compress the images
165
+ // of the srcset
158
166
  }
159
167
  else {
160
168
  // Generate image set
package/dist/options.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const default_options = {
2
2
  image: {
3
- embed_size: 0,
3
+ embed_size: 400,
4
4
  srcset_min_width: 400,
5
5
  srcset_max_width: 5120
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@divriots/jampack",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Packer for static websites",
5
5
  "author": "Georges Gomes @georges-gomes",
6
6
  "bin": {