Gruntjs concat& minify |选择替换目标文件中的代码而不是追加 [英] Gruntjs concat & minify | Option to replace the code in destination file instead of appending

查看:133
本文介绍了Gruntjs concat& minify |选择替换目标文件中的代码而不是追加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目开发过程中,我希望将JS和CSS文件合并到 global.js global.css 文件中,然后将它们缩小到全局.min.js global.min.css 使用 gruntjs 并使用这些在我的项目中缩小了文件。

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']);

};


推荐答案

在单独的目录中生成组合文件和缩小文件这些文件是由它们构成的。

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

这篇关于Gruntjs concat& minify |选择替换目标文件中的代码而不是追加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆