簡體   English   中英

cssmin和grunt-文件追加問題

[英]cssmin and grunt - file append issue

我剛剛開始使用gruntcssmin來實現CSS縮小過程的自動化。 初次運行時效果很好,但是稍后文件內容會附加到縮小的文件中,而不是覆蓋它,並且重復的文件大小會越來越大!

我的gruntfile.js文件內容如下。

module.exports = function (grunt) {
    grunt.initConfig({

    // define source files and their destinations
    cssmin: {
        target: {
            files: [{ 
                src: ['assets/front/css/*.css', '!*.min.css'],  // source files mask
                dest: 'assets/front/css/',    // destination folder
                expand: true,    // allow dynamic building
                flatten: true,   // remove all unnecessary nesting
                ext: '.min.css'   // replace .css to .min.css
            }],
        }
    },
    watch: {
        css:  { files: 'assets/front/css/*.css', tasks: [ 'cssmin' ] },
    }
});

// load plugins
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-cssmin');

// register at least this one task
grunt.registerTask('default', [ 'cssmin', 'watch' ]);


};

請告知,我在哪里犯錯。

我相信GitHub上的這個問題是相關的,其中討論了兩個解決方案:

1)在縮小之前使用清潔

   clean: ['your_path/css/*.min.css', '!your_path/css/*.css'],
   cssmin: {
      minify: {
        expand: true,
        cwd: 'your_path/css/',
        src: ['*.css'],
        dest: 'your_path/css/',
        ext: '.min.css'
      }
    }

2)使用絕對文件路徑,而不要使用* / **。css路徑,例如:

cssmin: {
  combine: {
    files: {
      'path/to/output.css': ['path/to/input_one.css', 'path/to/input_two.css']
    }
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM