D
D
dmytrotus2019-08-12 12:03:18
WordPress
dmytrotus, 2019-08-12 12:03:18

How to minify files in Wordpress using Gulpfile.js?

After installing the theme and plugins in Wordpress, there are a lot of requests to different css and js files.
I would like to optimize this whole thing and put it in one js file, as well as in another css file that will be minified.
For example, I throw off the list from css files

wp-includes/css/dashicons.min.css?ver=5.2.2
wp-includes/css/admin-bar.min.css?ver=5.2.2
wp-includes/css/dist/block-library/style.min.css?ver=5.2.2

wp-content/plugins/woocommerce/assets/css/blocks/style.css?ver=3.6.5
wp-content/plugins/yith-woocommerce-wishlist/assets/css/jquery.selectBox.css?ver=1.2.0
wp-content/plugins/yith-woocommerce-wishlist/assets/css/font-awesome.min.css?ver=4.7.0
wp-content/plugins/yith-woocommerce-wishlist/assets/css/style.css?ver=2.2.11
wp-content/plugins/contact-form-7/includes/css/styles.css?ver=5.1.4
wp-content/plugins/woocommerce/assets/css/woocommerce-layout.css?ver=3.6.5
wp-content/plugins/woocommerce/assets/css/woocommerce-smallscreen.css?ver=3.6.5
wp-content/plugins/woocommerce/assets/css/woocommerce.css?ver=3.6.5
wp-content/plugins/woocommerce/assets/css/prettyPhoto.css?ver=5.2.2

wp-content/themes/mytheme/style.css?ver=5.2.2
wp-content/themes/mytheme/assets/font-awesome/css/font-awesome.min.css?ver=5.2.2
wp-content/themes/mytheme/css/responsive.css?ver=5.2.2

All of them are in different folders.
Who will tell you what gulp modules to put in order not to put too much.
By the way, I only found in the documentation how to include one folder
. I understand Gulpfile.js should look like this
var minifyCSS = require('gulp-minify-css');
gulp.task('css', function(){
    gulp.src('src/css/**/*.css')
        .pipe(minifyCSS())
        .pipe(gulp.dest('themes/mytheme/css'))
});

What gulpfile.js and package.json files should be in the folder so that the npm i command can immediately put everything you need to compile js, css?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
EvgenyMorozov, 2019-08-12
@EvgenyMorozov

What will you do when plugin styles are updated along with plugins?
In my opinion, you only need to compress your theme's CSS and JS, and don't try to merge everything into one, it still won't work.
If you have a site on HTTPS, then transfer it to the HTTP / 2 protocol, here you can leave a lot of small style files and scripts.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question