如何编写适当的代码以使Grunt观看任何更改并保存

时间:2019-03-25 22:38:47

标签: gruntjs grunt-contrib-watch

我正在尝试为艰苦的任务运行者编写代码。我写了一些代码来缩小CSS和JS。我应该如何编写“ grunt watch”代码块?

当我在文件中进行更改并保存时,我手动编写了示例,例如“ grunt cssmin”。一切正常-CSS最小化。但是,当我等待“ grunt watch”时,任务运行程序等待更改,而当我修改css文件时,什么也没发生-grunt只是等待而不会缩小文件。

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        cssmin: {
            dist:{
                files: {
                '../css/about-section-css/style.min.css':'../css/about-section-css/style.css',
                '../css/flex-grid/style.min.css':'../css/flex-grid/style.css',
                '../css/general-css/style.min.css':'../css/general-css/style.css',
                '../css/header-css/style.min.css':'../css/header-css/style.css',
                '../css/js-classes/style.min.css':'../css/js-classes/style.css',
                '../css/partials-css/style.min.css':'../css/partials-css/style.css',
                '../css/preloader-css/style.min.css':'../css/preloader-css/style.css',
                '../css/skills-section-css/style.min.css':'../css/skills-section-css/style.css',
                '../css/swiper-css/style.min.css':'../css/swiper-css/style.css'
                }
            }
        },
        uglify: {
            options: {
                manage: false
            },
            dist:{
                files: {
                '../js/preloader.min.js':'../js/preloader.js',
                '../js/appear-plugin.min.js':'../js/appear-plugin.js',
                '../js/main-functions.min.js':'../js/main-functions.js',
                '../js/mobile-scripts.min.js':'../js/mobile-scripts.js',
                '../js/swiper.min.js':'../js/swiper.js'
                }
            }
        },
        watch: {
          css: {
            files: ['**/*.css'],
          },
          js: {
            files: ['**/*.js'],
          }
        }

    });

    grunt.loadNpmTasks('grunt-contrib-cssmin');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.registerTask('default', []);
}

0 个答案:

没有答案