2016-07-13 18 views
0

Ich benutze Grunt, um nach Änderungen in meinen Sass/Js-Dateien zu suchen und sie in meinen öffentlichen Ordner zu kompilieren. Ich habe eine Liveload-Funktion eingerichtet, die funktioniert, aber wenn ich meine js kompiliere, lädt das Livereload meine Seite 2 Mal neu, was ärgerlich ist. Ich denke, das liegt daran, dass ich mehrere JS-Dateien habe, die während der Überwachung erstellt werden (concat, minify).Livereload nur bei Änderungen im Öffentlichen Ordner

Also dachte ich, es wäre eine gute Idee, nur Änderungen in meinem öffentlichen Ordner neu zu laden, da ich (vorerst) nur eine js-Datei (uglify.js) und eine CSS-Datei (main.css) habe. Aber ich kann nicht sehen, wie ich das schaffen kann. Diese

ist, wie meine aktuelle gruntfile aussieht:

module.exports = function (grunt) { 

     // Project configuration. 
     grunt.initConfig({ 
      watch: { 
       watch_js_files: { 
        files: ['js/*.js'], 
        tasks: ['concat', 'minified', 'uglify'], 
       }, 
       watch_sass_files: { 
        files: ['css/*.scss'], 
        tasks: ['sass'], 
       } 
      }, 
      connect: { 
       server: { 
        options: { 
         open: true, 
         keepalive: true, 
         hostname: 'localhost', 
         port: 8080, 
         base: '' 
        } 
       } 
      }, 
      concat: { 
       dist: { 
        src: ['js/*.js'], 
        dest: 'js/min/concat.js' 
       }, 
      }, 
      minified: { 
       files: { 
        src: ['js/min/concat.js'], 
        dest: 'js/min/minified.js' 
       }, 
      }, 
      uglify: { 
       my_target: { 
        files: { 
         'public/js/uglify.js': ['js/min/minified.jsconcat.js'] 
        } 
       } 
      }, 
      sass: { 
       dist: { 
        files: { 
         'public/css/main.css': 'css/*.scss' 
        } 
       } 
      } 

     }); 

     grunt.loadNpmTasks('grunt-contrib-watch'); 
     grunt.loadNpmTasks('grunt-contrib-concat'); 
     grunt.loadNpmTasks('grunt-minified'); 
     grunt.loadNpmTasks('grunt-contrib-uglify'); 
     grunt.loadNpmTasks('grunt-contrib-sass'); 
     grunt.loadNpmTasks('grunt-contrib-connect'); 

    }; 

Antwort

0

ich einen Reload Aufgabe in meiner Uhr hinzugefügt haben:

 reload: { 
      files: ['*.html', 'public/css/*.css', 'public/js/*.js'], 
      options: { 
       livereload: true, 
       host: 'localhost', 
       port: 35729, 
      } 
     }, 

Und jetzt funktioniert es :)