grunt htmlmin - 无法让它缩小 htm,完美缩小 CSS 和 JS

问题描述 投票:0回答:1

concat 抓取所有 htm 页面并将它们放入 1,即 /templates/min/development.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

这是我在运行上面发布的代码时在终端窗口中得到的响应。

changing it to destination: source

@mario 阅读

production.htm
时似乎冻结了。

grunt version

这和我的 grunt 版本有关系吗?我必须有 4.0 版本吗?我的是4.5,还可以用吗?还有许多其他错误,其中任何一个都敲响了我的 html 为何没有缩小的警钟?

gruntjs grunt-contrib-htmlmin
1个回答
0
投票

根据htmlmin文档,你必须这样写任务:

    htmlmin: {
        controlHtml: {
            options: {
                removeComments: true,
                collapseWhitespace: true
            },
            files: {
                 'UI.controls/assets/templates/min/production.htm': 'UI.controls/assets/templates/min/production.min.htm'
            }
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.