sdc-build-wp 4.4.1 → 4.5.1

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.
@@ -1,8 +1,7 @@
1
1
  import BaseComponent from './base.js';
2
- import imagemin from 'imagemin';
3
- import imageminJpegtran from 'imagemin-jpegtran';
4
- import imageminPngquant from 'imagemin-pngquant';
5
- import imageminSvgo from 'imagemin-svgo';
2
+ import { promises as fs } from 'fs';
3
+ import sharp from 'sharp';
4
+ import { optimize } from 'svgo';
6
5
 
7
6
  export default class ImagesComponent extends BaseComponent {
8
7
 
@@ -26,17 +25,42 @@ export default class ImagesComponent extends BaseComponent {
26
25
  async build(entry, options) {
27
26
  let timerStart = Date.now();
28
27
  let dest = entry.replace(`${this.project.paths.src.src}/${this.project.paths.src.images}`, `${this.project.paths.dist}/${this.project.paths.src.images}`);
29
- const files = await imagemin([entry + '/*'], {
30
- destination: dest,
31
- plugins: [
32
- imageminJpegtran(),
33
- imageminPngquant(),
34
- imageminSvgo()
35
- ]
36
- });
28
+ const files = await fs.readdir(entry);
29
+ await fs.mkdir(dest, { recursive: true });
30
+
31
+ let convertedImagesCount = 0;
32
+ let copiedFilesCount = 0;
33
+ for (const file of files) {
34
+ const filePath = this.path.join(entry, file);
35
+ const destFilePath = `${dest}/${this.path.basename(file)}`;
36
+ if (this.path.extname(file).toLowerCase() == '.webmanifest') {
37
+ await fs.copyFile(filePath, destFilePath);
38
+ copiedFilesCount++;
39
+ continue;
40
+ }
41
+ if (!['.jpg', '.jpeg', '.png', '.svg'].includes(this.path.extname(file).toLowerCase())) { continue; }
42
+ try {
43
+ if (this.path.extname(file) == '.svg') {
44
+ const result = optimize(await fs.readFile(filePath, 'utf8'), {
45
+ multipass: true,
46
+ plugins: [
47
+ 'preset-default'
48
+ ]
49
+ });
50
+ await fs.writeFile(destFilePath, result.data);
51
+ } else {
52
+ await sharp(filePath).toFile(destFilePath);
53
+ }
54
+ convertedImagesCount++;
55
+ } catch (error) {
56
+ console.error(error);
57
+ this.log('error', `Failed optimizing ${filePath.replace(this.project.path, '')} - See above error.`);
58
+ }
59
+
60
+ }
37
61
 
38
62
  this.end({
39
- itemLabel: `${dest.replace(this.project.path, '')} (${files.length} image${files.length == 1 ? '' : 's'})`,
63
+ itemLabel: `${dest.replace(this.project.path, '')} (${convertedImagesCount} image${convertedImagesCount == 1 ? '' : 's'}${copiedFilesCount ? `, ${copiedFilesCount} file${copiedFilesCount == 1 ? '' : 's'}` : ''})`,
40
64
  timerStart: timerStart,
41
65
  timerEnd: Date.now()
42
66
  });
@@ -16,6 +16,7 @@ export default class ServerComponent extends BaseComponent {
16
16
  start() {
17
17
  let watchedFiles = [
18
18
  `${this.project.path}/${this.project.paths.dist}/**/*`,
19
+ `!**/*.map`,
19
20
  `${this.project.path}/**/*.html`,
20
21
  `${this.project.path}/**/*.json`,
21
22
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdc-build-wp",
3
- "version": "4.4.1",
3
+ "version": "4.5.1",
4
4
  "description": "Custom WordPress build process.",
5
5
  "engines": {
6
6
  "node": ">=22"
@@ -33,17 +33,15 @@
33
33
  "esbuild": "^0.25.1",
34
34
  "eslint": "^9.22.0",
35
35
  "fs-extra": "^11.3.0",
36
- "imagemin": "^9.0.1",
37
- "imagemin-jpegtran": "^8.0.0",
38
- "imagemin-pngquant": "^10.0.0",
39
- "imagemin-svgo": "^11.0.1",
40
36
  "jiti": "^2.4.2",
41
37
  "minimist": "^1.2.8",
42
38
  "postcss": "^8.5.3",
43
39
  "postcss-scss": "^4.0.9",
44
40
  "postcss-sort-media-queries": "^5.2.0",
45
41
  "sass": "^1.85.1",
42
+ "sharp": "^0.33.5",
46
43
  "stylelint": "^16.16.0",
44
+ "svgo": "^3.3.2",
47
45
  "tail": "^2.2.6"
48
46
  }
49
47
  }