How to watch sass and javascript at the same time in gulp 42019 Community Moderator ElectionHow to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I check if an array includes an object in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

Is "history" a male-biased word ("his+story")?

Bash script should only kill those instances of another script's that it has launched

Why is computing ridge regression with a Cholesky decomposition much quicker than using SVD?

How did Alan Turing break the enigma code using the hint given by the lady in the bar?

How is the wildcard * interpreted as a command?

'The literal of type int is out of range' con número enteros pequeños (2 dígitos)

When traveling to Europe from North America, do I need to purchase a different power strip?

Filtering SOQL results with optional conditionals

List elements digit difference sort

How strictly should I take "Candidates must be local"?

Conservation of Mass and Energy

Do I really need to have a scientific explanation for my premise?

Latex does not go to next line

Hotkey (or other quick way) to insert a keyframe for only one component of a vector-valued property?

Was Luke Skywalker the leader of the Rebel forces on Hoth?

What Happens when Passenger Refuses to Fly Boeing 737 Max?

In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?

PTIJ: wiping amalek’s memory?

They call me Inspector Morse

Could you please stop shuffling the deck and play already?

Are tamper resistant receptacles really safer?

Doesn't allowing a user mode program to access kernel space memory and execute the IN and OUT instructions defeat the purpose of having CPU modes?

weren't playing vs didn't play

Accepted offer letter, position changed



How to watch sass and javascript at the same time in gulp 4



2019 Community Moderator ElectionHow to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I check if an array includes an object in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?










1















I am trying to convert my sass to compressed-css and javascript to uglified-js. And watch both scss and js changes



my code is working but when I tried saving a js file, it goes into a unstoppable loop.



Here is my code:



var gulp = require('gulp');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');

gulp.task('sass', function(done)

gulp.src('public/sass/**/*.scss')
.pipe(sass(outputStyle: 'compressed')) // Using gulp-sass
.pipe(gulp.dest('public/stylesheets'))

done();
);

gulp.task('scripts', function(done)

gulp.src('public/javascripts/**/*.js')
.pipe(concat('scripts.js'))
.pipe(uglify())
.pipe(gulp.dest('public/javascripts'))

done();
);


gulp.task('watch', function()
//I made .scss and .js into an array so they will both be watched
gulp.watch(['public/sass/**/*.scss', 'public/javascripts/**/*.js' ], gulp.series('sass', 'scripts', function(done)


done();
))
)


Now when I run gulp watch it is working but then when I save a js file, I goes into a saving loop, It's saves and saves and saves nonstop.



I have made scss work with this code



 gulp.task('watch', function()
gulp.watch('public/sass/**/*.scss', gulp.series('sass', 'scripts', function(done)


done();
))
)


But I have no idea how I can make .js files be watched.



I searched google for possible answer but only find the older version solution. Is there a way I can do this with gulp4?



  • I also tried gulp.parallel but it still looped

Please help. Thanks










share|improve this question


























    1















    I am trying to convert my sass to compressed-css and javascript to uglified-js. And watch both scss and js changes



    my code is working but when I tried saving a js file, it goes into a unstoppable loop.



    Here is my code:



    var gulp = require('gulp');
    var sass = require('gulp-sass');
    var uglify = require('gulp-uglify');
    var concat = require('gulp-concat');

    gulp.task('sass', function(done)

    gulp.src('public/sass/**/*.scss')
    .pipe(sass(outputStyle: 'compressed')) // Using gulp-sass
    .pipe(gulp.dest('public/stylesheets'))

    done();
    );

    gulp.task('scripts', function(done)

    gulp.src('public/javascripts/**/*.js')
    .pipe(concat('scripts.js'))
    .pipe(uglify())
    .pipe(gulp.dest('public/javascripts'))

    done();
    );


    gulp.task('watch', function()
    //I made .scss and .js into an array so they will both be watched
    gulp.watch(['public/sass/**/*.scss', 'public/javascripts/**/*.js' ], gulp.series('sass', 'scripts', function(done)


    done();
    ))
    )


    Now when I run gulp watch it is working but then when I save a js file, I goes into a saving loop, It's saves and saves and saves nonstop.



    I have made scss work with this code



     gulp.task('watch', function()
    gulp.watch('public/sass/**/*.scss', gulp.series('sass', 'scripts', function(done)


    done();
    ))
    )


    But I have no idea how I can make .js files be watched.



    I searched google for possible answer but only find the older version solution. Is there a way I can do this with gulp4?



    • I also tried gulp.parallel but it still looped

    Please help. Thanks










    share|improve this question
























      1












      1








      1








      I am trying to convert my sass to compressed-css and javascript to uglified-js. And watch both scss and js changes



      my code is working but when I tried saving a js file, it goes into a unstoppable loop.



      Here is my code:



      var gulp = require('gulp');
      var sass = require('gulp-sass');
      var uglify = require('gulp-uglify');
      var concat = require('gulp-concat');

      gulp.task('sass', function(done)

      gulp.src('public/sass/**/*.scss')
      .pipe(sass(outputStyle: 'compressed')) // Using gulp-sass
      .pipe(gulp.dest('public/stylesheets'))

      done();
      );

      gulp.task('scripts', function(done)

      gulp.src('public/javascripts/**/*.js')
      .pipe(concat('scripts.js'))
      .pipe(uglify())
      .pipe(gulp.dest('public/javascripts'))

      done();
      );


      gulp.task('watch', function()
      //I made .scss and .js into an array so they will both be watched
      gulp.watch(['public/sass/**/*.scss', 'public/javascripts/**/*.js' ], gulp.series('sass', 'scripts', function(done)


      done();
      ))
      )


      Now when I run gulp watch it is working but then when I save a js file, I goes into a saving loop, It's saves and saves and saves nonstop.



      I have made scss work with this code



       gulp.task('watch', function()
      gulp.watch('public/sass/**/*.scss', gulp.series('sass', 'scripts', function(done)


      done();
      ))
      )


      But I have no idea how I can make .js files be watched.



      I searched google for possible answer but only find the older version solution. Is there a way I can do this with gulp4?



      • I also tried gulp.parallel but it still looped

      Please help. Thanks










      share|improve this question














      I am trying to convert my sass to compressed-css and javascript to uglified-js. And watch both scss and js changes



      my code is working but when I tried saving a js file, it goes into a unstoppable loop.



      Here is my code:



      var gulp = require('gulp');
      var sass = require('gulp-sass');
      var uglify = require('gulp-uglify');
      var concat = require('gulp-concat');

      gulp.task('sass', function(done)

      gulp.src('public/sass/**/*.scss')
      .pipe(sass(outputStyle: 'compressed')) // Using gulp-sass
      .pipe(gulp.dest('public/stylesheets'))

      done();
      );

      gulp.task('scripts', function(done)

      gulp.src('public/javascripts/**/*.js')
      .pipe(concat('scripts.js'))
      .pipe(uglify())
      .pipe(gulp.dest('public/javascripts'))

      done();
      );


      gulp.task('watch', function()
      //I made .scss and .js into an array so they will both be watched
      gulp.watch(['public/sass/**/*.scss', 'public/javascripts/**/*.js' ], gulp.series('sass', 'scripts', function(done)


      done();
      ))
      )


      Now when I run gulp watch it is working but then when I save a js file, I goes into a saving loop, It's saves and saves and saves nonstop.



      I have made scss work with this code



       gulp.task('watch', function()
      gulp.watch('public/sass/**/*.scss', gulp.series('sass', 'scripts', function(done)


      done();
      ))
      )


      But I have no idea how I can make .js files be watched.



      I searched google for possible answer but only find the older version solution. Is there a way I can do this with gulp4?



      • I also tried gulp.parallel but it still looped

      Please help. Thanks







      javascript gulp






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 6 at 15:22









      bradrarbradrar

      1037




      1037






















          2 Answers
          2






          active

          oldest

          votes


















          1














          Your original code:



          gulp.task('watch', function()
          //I made .scss and .js into an array so they will both be watched
          gulp.watch(['public/sass/**/*.scss', 'public/javascripts/**/*.js' ], gulp.series('sass', 'scripts', function(done)

          done();
          ))
          )


          should be



          gulp.task('watch', function(done)

          // added done above too

          gulp.watch('public/sass/**/*.scss', gulp.series('sass') )
          gulp.watch('public/javascripts/**/*.js', gulp.series('scripts') )
          done();
          )


          Your code triggers both 'sass' and 'scripts' tasks when either a scss or js file is modified, which is wasteful (for example, the 'sass' task will start when a js file is altered but not actually do anything with that js file but will needlessly run the sass re-compilation although no scss file changed).






          share|improve this answer























          • Thank you for this, I am new to gulp and all the tutorials I saw is extremely difficult to understand.

            – bradrar
            Mar 7 at 18:19


















          0














          I solved this by doing this:



           gulp.task('watch', function()
          //I added the src folder instead of the glob **(two asterisk)
          gulp.watch(['public/sass/**/*.scss', 'public/javascripts/src/*.js'], gulp.series('sass', 'scripts', function(done)


          done();
          ))


          )



          I don't know why this happened but it's working now






          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55026517%2fhow-to-watch-sass-and-javascript-at-the-same-time-in-gulp-4%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Your original code:



            gulp.task('watch', function()
            //I made .scss and .js into an array so they will both be watched
            gulp.watch(['public/sass/**/*.scss', 'public/javascripts/**/*.js' ], gulp.series('sass', 'scripts', function(done)

            done();
            ))
            )


            should be



            gulp.task('watch', function(done)

            // added done above too

            gulp.watch('public/sass/**/*.scss', gulp.series('sass') )
            gulp.watch('public/javascripts/**/*.js', gulp.series('scripts') )
            done();
            )


            Your code triggers both 'sass' and 'scripts' tasks when either a scss or js file is modified, which is wasteful (for example, the 'sass' task will start when a js file is altered but not actually do anything with that js file but will needlessly run the sass re-compilation although no scss file changed).






            share|improve this answer























            • Thank you for this, I am new to gulp and all the tutorials I saw is extremely difficult to understand.

              – bradrar
              Mar 7 at 18:19















            1














            Your original code:



            gulp.task('watch', function()
            //I made .scss and .js into an array so they will both be watched
            gulp.watch(['public/sass/**/*.scss', 'public/javascripts/**/*.js' ], gulp.series('sass', 'scripts', function(done)

            done();
            ))
            )


            should be



            gulp.task('watch', function(done)

            // added done above too

            gulp.watch('public/sass/**/*.scss', gulp.series('sass') )
            gulp.watch('public/javascripts/**/*.js', gulp.series('scripts') )
            done();
            )


            Your code triggers both 'sass' and 'scripts' tasks when either a scss or js file is modified, which is wasteful (for example, the 'sass' task will start when a js file is altered but not actually do anything with that js file but will needlessly run the sass re-compilation although no scss file changed).






            share|improve this answer























            • Thank you for this, I am new to gulp and all the tutorials I saw is extremely difficult to understand.

              – bradrar
              Mar 7 at 18:19













            1












            1








            1







            Your original code:



            gulp.task('watch', function()
            //I made .scss and .js into an array so they will both be watched
            gulp.watch(['public/sass/**/*.scss', 'public/javascripts/**/*.js' ], gulp.series('sass', 'scripts', function(done)

            done();
            ))
            )


            should be



            gulp.task('watch', function(done)

            // added done above too

            gulp.watch('public/sass/**/*.scss', gulp.series('sass') )
            gulp.watch('public/javascripts/**/*.js', gulp.series('scripts') )
            done();
            )


            Your code triggers both 'sass' and 'scripts' tasks when either a scss or js file is modified, which is wasteful (for example, the 'sass' task will start when a js file is altered but not actually do anything with that js file but will needlessly run the sass re-compilation although no scss file changed).






            share|improve this answer













            Your original code:



            gulp.task('watch', function()
            //I made .scss and .js into an array so they will both be watched
            gulp.watch(['public/sass/**/*.scss', 'public/javascripts/**/*.js' ], gulp.series('sass', 'scripts', function(done)

            done();
            ))
            )


            should be



            gulp.task('watch', function(done)

            // added done above too

            gulp.watch('public/sass/**/*.scss', gulp.series('sass') )
            gulp.watch('public/javascripts/**/*.js', gulp.series('scripts') )
            done();
            )


            Your code triggers both 'sass' and 'scripts' tasks when either a scss or js file is modified, which is wasteful (for example, the 'sass' task will start when a js file is altered but not actually do anything with that js file but will needlessly run the sass re-compilation although no scss file changed).







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 6 at 23:08









            MarkMark

            14.1k34058




            14.1k34058












            • Thank you for this, I am new to gulp and all the tutorials I saw is extremely difficult to understand.

              – bradrar
              Mar 7 at 18:19

















            • Thank you for this, I am new to gulp and all the tutorials I saw is extremely difficult to understand.

              – bradrar
              Mar 7 at 18:19
















            Thank you for this, I am new to gulp and all the tutorials I saw is extremely difficult to understand.

            – bradrar
            Mar 7 at 18:19





            Thank you for this, I am new to gulp and all the tutorials I saw is extremely difficult to understand.

            – bradrar
            Mar 7 at 18:19













            0














            I solved this by doing this:



             gulp.task('watch', function()
            //I added the src folder instead of the glob **(two asterisk)
            gulp.watch(['public/sass/**/*.scss', 'public/javascripts/src/*.js'], gulp.series('sass', 'scripts', function(done)


            done();
            ))


            )



            I don't know why this happened but it's working now






            share|improve this answer



























              0














              I solved this by doing this:



               gulp.task('watch', function()
              //I added the src folder instead of the glob **(two asterisk)
              gulp.watch(['public/sass/**/*.scss', 'public/javascripts/src/*.js'], gulp.series('sass', 'scripts', function(done)


              done();
              ))


              )



              I don't know why this happened but it's working now






              share|improve this answer

























                0












                0








                0







                I solved this by doing this:



                 gulp.task('watch', function()
                //I added the src folder instead of the glob **(two asterisk)
                gulp.watch(['public/sass/**/*.scss', 'public/javascripts/src/*.js'], gulp.series('sass', 'scripts', function(done)


                done();
                ))


                )



                I don't know why this happened but it's working now






                share|improve this answer













                I solved this by doing this:



                 gulp.task('watch', function()
                //I added the src folder instead of the glob **(two asterisk)
                gulp.watch(['public/sass/**/*.scss', 'public/javascripts/src/*.js'], gulp.series('sass', 'scripts', function(done)


                done();
                ))


                )



                I don't know why this happened but it's working now







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 6 at 15:52









                bradrarbradrar

                1037




                1037



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55026517%2fhow-to-watch-sass-and-javascript-at-the-same-time-in-gulp-4%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                    Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                    Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved