grunt htmlmin - 无法让它缩小htm请帮助,完美地缩小css和js

时间:2014-10-01 15:23:32

标签: gruntjs grunt-contrib-htmlmin

concat抓取所有htm页面并将它们放入1,即/templates/min/production.htm

我想要实现的是/templates/min/production.min.htm,我在终端窗口没有错误...如果你们想进一步了解,请告诉我

module.exports = function (grunt) {

    // 1. All configuration goes here
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        concat: {
            controlCss: {
                src: ['UI.controls/assets/css/*.css'],
                dest: 'UI.controls/assets/css/min/production.css'
            },

            controlJs: {
                src: ['UI.controls/assets/js/*.js'],
                dest: 'UI.controls/assets/js/min/production.js'
            },

            coreJs: {
                src: ['UI.core/assets/js/*.js'],
                dest: 'UI.core/assets/js/min/production.js'
            }

            ,
            controlHtml: {
                src: ['UI.controls/assets/templates/*.htm'],
                dest: 'UI.controls/assets/templates/min/production.htm'
            }
        },

        cssmin: {
            controlCss: {
                src: 'UI.controls/assets/css/min/production.css',
                dest: 'UI.controls/assets/css/min/production.min.css'
            }
        },

        uglify: {
            controlJs: {
                src: 'UI.controls/assets/js/min/production.js',
                dest: 'UI.controls/assets/js/min/production.min.js'
            },

            coreJs: {
                src: 'UI.core/assets/js/min/production.js',
                dest: 'UI.core/assets/js/min/production.min.js'
            }
        },


        htmlmin: {
            controlHtml: {
                options: {
                    removeComments: true,
                    collapseWhitespace: true
                },
                expand: true,
                cwd: 'expand',
                src: 'UI.controls/assets/templates/min/production.htm',
                dest: 'UI.controls/assets/templates/min/production.min.htm'
            }
        }



    });

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

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

};

@mario your way

@mario这是以你的方式运行代码,它似乎找不到源文件...但我认为它假设是目的地:源...不是源:目的地..我要发布我在做目的地时得到的回应:来源

@mario my way ie my code posted above

这是我在终端窗口中运行代码的响应,正如我在@mario

上面发布的那样

![changing it to destination: source] 4

@mario在阅读production.htm时似乎很冷淡:(感谢你的帮助

grunt version

与我的咕噜声版本有什么关系吗?我必须有4.0版本吗?我有4.5 ..它还能用吗? 还有很多其他的错误...他们中的任何一个都响了为什么我的html没有缩小?感谢任何帮助。提前致谢

1 个答案:

答案 0 :(得分:0)

根据htmlmin documentation,您必须编写如下任务:

    htmlmin: {
        controlHtml: {
            options: {
                removeComments: true,
                collapseWhitespace: true
            },
            files: {
                 'UI.controls/assets/templates/min/production.htm': 'UI.controls/assets/templates/min/production.min.htm'
            }
        }
    }

希望它有所帮助。

问候。