0

I would like to run gulp task on save button on .css file to minify file. I have tried gulp.watch but it is not working.

Is there any other way to minify file on save button. Using Sitecore 9.1.1.

CLI version: 2.3.0
Local version: 4.0.2
5
  • Can you explain a bit more in detail? What save button are you talking about? Some button in Sitecore? Dec 6 '21 at 14:05
  • @JonKoivula, I am talking about Ctrl+S (Save any file through ctrl+s combination button)
    – Ashish
    Dec 6 '21 at 15:30
  • Where are you pressing Ctrl + S`? Update the question with more information as the amount of information you have said is not clear. And how this is related to Sitecore? Dec 6 '21 at 22:53
  • I have already mentioned save button on .css file. What kind of information do you need ?
    – Ashish
    Dec 7 '21 at 7:20
  • If this issue is not about Sitecore then this is a wrong place to ask question of this. You should go to stackoverflow instead of here. Here you should only ask questions regarding to Sitecore. Dec 7 '21 at 9:23
2

I have resolved this issue.

I have found two ways to resolve this issue.

1) gulp.watch
2) Bundler & Minifier Extension

gulp.watch :

gulp.task('minify:css',async function () {
    gulp.src('./css/*.css')
        .pipe(minifyCSS())
        .pipe(gulp.dest('minified')
        );
});

gulp.task("watch",() => {
    gulp.watch("./css/*.css", gulp.series('minify:css'));
});

gulp.task('default', gulp.series('minify:css', 'watch'));

We need to click on default task on Task runner explorer to add the changes automatically in minified file.

I am using gulp version 4 so using gulp.series .If you are using gulp version 3 then you can use this code

gulp.task("watch",() => {
    gulp.watch('./css/*.css',['minify:css']);
});
    gulp.task('default', ['minify:css', 'watch']);

Instead of

gulp.task("watch",() => {
    gulp.watch("./css/*.css", gulp.series('minify:css'));
});

gulp.task('default', gulp.series('minify:css', 'watch'));

Bundler & Minifier Extension

Found extension to automatically minified file by follow the steps in the below link https://marketplace.visualstudio.com/items?itemName=MadsKristensen.BundlerMinifier

We can add this extension in our project. enter image description here

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.