Gruntjs concat & minify | Option to replace the code in destination file instead of appending

送分小仙女□ 提交于 2020-01-06 12:43:17

问题


Throughout the course of my project development I wish to combine JS and CSS files into global.js and global.css files and then minify them into global.min.js and global.min.css using gruntjs and use these minified files in my project.

But everytime I run the commands it cancats/combines the files and adds the combined codes to the global files(Causing redundancy) instead of replacing those global files with the new combined codes. Is there any option for it or any other plugin to prevent that?

module.exports = function(grunt) {

// 1. All configuration goes here 
grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    concat: {   
        dist: {
            src: [
                'js/**/*.js',
                'js/*.js'
            ],
            dest: 'js/global.js',
        }
    },


    uglify: {
        build: {
            src: 'js/global.js',
            dest: 'js/global.min.js'
        }
    },

    cssmin: {
      combine: {
        files: {
          'css/global.css': ['css/*.css','css/**/*.css']
        }
      },

       minify: {
        src: 'css/global.css',
        dest: 'css/global.min.css'
      }
    },     


});

// 3. Where we tell Grunt we plan to use this plug-in.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-watch');

// 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
grunt.registerTask('default', ['concat', 'uglify', 'cssmin']);

};

回答1:


Generate the combined and minified files in a separate directory to the files that they are made up from.



来源:https://stackoverflow.com/questions/20866937/gruntjs-concat-minify-option-to-replace-the-code-in-destination-file-instead

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!