How to setup Gruntfile.js to watch for SASS (compass) and JS

前端 未结 1 1963
独厮守ぢ
独厮守ぢ 2021-01-19 01:58

I\'m new to using gruntjs and nodejs. I wanted to know how can I setup the gruntfile so that it watches both the sass files and the js files compiles using watch.

Th

相关标签:
1条回答
  • 2021-01-19 02:25

    Try grunt-contrib-watch with grunt-contrib-sass. They're both Grunt plugins specifically for this kind of thing:

        sass: {
            dist: {
                options: {
                    style: 'compressed'
                },
                files: {
                    'css/build/global.css': 'scss/screen.scss'
                }
            } 
        },
    
    
        watch: {
    
            css: {
                files: ['scss/*.scss'],
                tasks: ['sass'],
                options: {
                    spawn: false
                }
            } 
        },
    

    The watch plugin configuration above will watch for changes in any .scss files, and will run the sass tasked (also defined above). You can even hook into livereload this way. You can also have multiple watches (the above only defines a css watch); creating a second watch to minify JS would be easy with grunt-contrib-uglify

    I have an example you can look at that also concatenates JavaScript and does some minification with grunt-contrib-uglify. Here is the example.

    0 讨论(0)
提交回复
热议问题