R
R
Rokis2017-03-04 07:25:18
Node.js
Rokis, 2017-03-04 07:25:18

How to optimize images with gulp-tinypng on the server?

Hello. I installed the gulp-tinypng
plugin on my server ( ubuntu 16.04 ) , but I don't understand how it works. There is no detailed instruction on google as I suspect it is very simple in terms of programming.

var gulp = require('gulp');
var imagemin = require('gulp-tinypng');
 
gulp.task('tinypng', function () {
    gulp.src('src/image.png')
        .pipe(tingpng('API_KEY'))
        .pipe(gulp.dest('dist'));
});

I created a new file: I
nano /node_modules/gulp-tinypng/jim.js
wrote the following code in it based on this example:
var gulp = require('gulp');
var imagemin = require('gulp-tinypng');
 
gulp.task('tinypng', function () {
    gulp.src('/var/www/*.png')
    gulp.src('/var/www/*.jpg')
        .pipe(tingpng('мой_ключ'))
        .pipe(gulp.dest(''));
});

After running the script, nothing happens.
Here is a list of questions that I have:
1) How do I overwrite files in the same place? (is it in gulp.dest?)
2) What needs to be fixed in the script to make it work? (if it's not difficult, a working example)
3) What additional modules/libraries can be disabled in node.js and gulp? (only the image compression function is needed)
4) How else can tinypng API be implemented on the server? (maybe something simpler)
I need to compress all the images on the site with this service. That is, I want to specify the path to the directory with the site and so that the images (jpg and png) in it are optimized without changing their place ( overwritten). I am far from programming and will be glad for any help in solving this problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Magomedov Magomed, 2018-03-19
@killer07

It doesn't work because you connect the plugin as: but you use it as tingpng This will work

var tingpng= require('gulp-tinypng');

gulp.task('tinypng', function () {
    gulp.src('/var/www/*.png')
    gulp.src('/var/www/*.jpg')
        .pipe(tingpng('мой_ключ'))
        .pipe(gulp.dest(''));
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question