@nitro/gulp 11.0.0-beta.1 → 11.0.0-beta.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitro/gulp",
3
- "version": "11.0.0-beta.1",
3
+ "version": "11.0.0-beta.3",
4
4
  "description": "Nitro gulp",
5
5
  "license": "MIT",
6
6
  "author": "The Nitro Team",
@@ -23,12 +23,12 @@
23
23
  "gulp"
24
24
  ],
25
25
  "peerDependencies": {
26
- "@nitro/app": ">=11.0.0-beta.1",
26
+ "@nitro/app": ">=11.0.0-beta.3",
27
27
  "gulp": ">=5.0.0"
28
28
  },
29
29
  "dependencies": {
30
30
  "compression": "1.8.1",
31
- "config": "4.2.1",
31
+ "config": "4.3.0",
32
32
  "del": "8.0.1",
33
33
  "get-port": "7.1.0",
34
34
  "gulp": "5.0.1",
@@ -1,65 +1,78 @@
1
- 'use strict';
2
-
3
- const config = require('config');
4
- const ordered = require('ordered-read-streams');
5
- const utils = require('../lib/utils');
6
-
7
- async function loadImageminPlugins() {
8
- const plugins = [];
9
-
10
- try {
11
- const mozjpeg = (await import('imagemin-mozjpeg')).default;
12
- plugins.push(mozjpeg({ quality: 75, progressive: true }));
13
- } catch { /* empty */ }
14
-
15
- try {
16
- const optipng = (await import('imagemin-optipng')).default;
17
- plugins.push(optipng({ optimizationLevel: 7 }));
18
- } catch { /* empty */ }
19
-
20
- try {
21
- const pngquant = (await import('imagemin-pngquant')).default;
22
- plugins.push(pngquant());
23
- } catch { /* empty */ }
24
-
25
- try {
26
- const svgo = (await import('imagemin-svgo')).default;
27
- plugins.push(svgo({
28
- plugins: [
29
- { name: 'collapseGroups', active: false },
30
- // { name: 'cleanupIDs', active: false },
31
- { name: 'removeUnknownsAndDefaults', active: false },
32
- { name: 'removeViewBox', active: false },
33
- ],
34
- }));
35
- } catch { /* empty */ }
36
-
37
- return plugins;
38
- }
39
-
40
- module.exports = (gulp, plugins) => {
41
-
42
- return async () => {
43
- const minifyImagesConfigs = config.has('gulp.minifyImages') ? config.get('gulp.minifyImages') : {};
44
- const imageminPlugins = await loadImageminPlugins();
45
- const imagemin = (await import('gulp-imagemin')).default;
46
-
47
- const streams = [];
48
-
49
- utils.each(minifyImagesConfigs, (minifyImagesConfig) => {
50
- if (minifyImagesConfig && minifyImagesConfig.src && minifyImagesConfig.dest) {
51
- streams.push(
52
- gulp
53
- .src(minifyImagesConfig.src, { encoding: false })
54
- .pipe(plugins.newer(minifyImagesConfig.dest))
55
- .pipe(
56
- imagemin(imageminPlugins)
57
- )
58
- .pipe(gulp.dest(minifyImagesConfig.dest))
59
- );
60
- }
61
- });
62
-
63
- return streams.length ? ordered(streams) : Promise.resolve('resolved');
64
- };
65
- };
1
+ 'use strict';
2
+
3
+ const config = require('config');
4
+ const ordered = require('ordered-read-streams');
5
+ const utils = require('../lib/utils');
6
+
7
+ async function loadImageminPlugins() {
8
+ const plugins = [];
9
+
10
+ try {
11
+ const mozjpeg = (await import('imagemin-mozjpeg')).default;
12
+ plugins.push(mozjpeg({ quality: 75, progressive: true }));
13
+ } catch { /* empty */ }
14
+
15
+ try {
16
+ const optipng = (await import('imagemin-optipng')).default;
17
+ plugins.push(optipng({ optimizationLevel: 7 }));
18
+ } catch { /* empty */ }
19
+
20
+ try {
21
+ const pngquant = (await import('imagemin-pngquant')).default;
22
+ plugins.push(pngquant());
23
+ } catch { /* empty */ }
24
+
25
+ try {
26
+ const svgo = (await import('imagemin-svgo')).default;
27
+ plugins.push(svgo({
28
+ plugins: [
29
+ { name: 'collapseGroups', active: false },
30
+ // { name: 'cleanupIDs', active: false },
31
+ { name: 'removeUnknownsAndDefaults', active: false },
32
+ { name: 'removeViewBox', active: false },
33
+ ],
34
+ }));
35
+ } catch { /* empty */ }
36
+
37
+ return plugins;
38
+ }
39
+
40
+ module.exports = (gulp, plugins) => {
41
+
42
+ return (done) => {
43
+ const minifyImagesConfigs = config.has('gulp.minifyImages') ? config.get('gulp.minifyImages') : {};
44
+
45
+ Promise.all([loadImageminPlugins(), import('gulp-imagemin')])
46
+ .then(([imageminPlugins, imageminModule]) => {
47
+ const imagemin = imageminModule.default;
48
+ const streams = [];
49
+
50
+ utils.each(minifyImagesConfigs, (minifyImagesConfig) => {
51
+ if (minifyImagesConfig && minifyImagesConfig.src && minifyImagesConfig.dest) {
52
+ const srcStream = gulp.src(minifyImagesConfig.src, { encoding: false, allowEmpty: true });
53
+
54
+ streams.push(
55
+ srcStream
56
+ .pipe(plugins.newer(minifyImagesConfig.dest))
57
+ .pipe(
58
+ imagemin(imageminPlugins)
59
+ )
60
+ .pipe(gulp.dest(minifyImagesConfig.dest))
61
+ );
62
+ }
63
+ });
64
+
65
+ if (!streams.length) {
66
+ done();
67
+ return;
68
+ }
69
+
70
+ const merged = ordered(streams);
71
+ merged.on('error', done);
72
+ merged.on('finish', done);
73
+ merged.on('end', done);
74
+ merged.resume();
75
+ })
76
+ .catch(done);
77
+ };
78
+ };