sdc-build-wp 4.4.0 → 4.5.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.
@@ -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
  });
@@ -53,7 +53,7 @@ export default class ScriptsComponent extends BaseComponent {
53
53
  outdir: `${this.project.paths.dist}/${this.project.paths.src.scripts}/`,
54
54
  entryNames: '[dir]/[name].min',
55
55
  plugins: [],
56
- sourcemap: true
56
+ sourcemap: process.env.NODE_ENV == 'production' ? false : true
57
57
  });
58
58
  if (result.warnings.length > 0) {
59
59
  log('warn', result.warnings);
@@ -116,13 +116,23 @@ export default class StyleComponent extends BaseComponent {
116
116
  throw Error('Linting error');
117
117
  }
118
118
  const compileResult = await sass.compileAsync(entry, {
119
- style: 'compressed'
119
+ style: 'compressed',
120
+ sourceMap: true
120
121
  });
121
122
  const postcssResult = await postcss([
122
123
  autoprefixer(),
123
124
  sortMQ()
124
- ]).process(compileResult.css, { from: undefined });
125
+ ]).process(compileResult.css, {
126
+ from: undefined,
127
+ to: outFile,
128
+ map: {
129
+ inline: false
130
+ }
131
+ });
125
132
  await fs.writeFile(outFile, postcssResult.css);
133
+ if (process.env.NODE_ENV != 'production') {
134
+ await fs.writeFile(`${outFile}.map`, postcssResult.map.toString());
135
+ }
126
136
  thisClass.end({
127
137
  itemLabel: entryLabel
128
138
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdc-build-wp",
3
- "version": "4.4.0",
3
+ "version": "4.5.0",
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
  }