【问题标题】:grunt htmlmin - cannot get it to minify htm please help, minifies css and js perfectlygrunt htmlmin - 无法让它缩小 htm 请帮助,完美缩小 css 和 js
【发布时间】:2014-10-01 15:23:31
【问题描述】:

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 这是按照你的方式运行代码,它似乎找不到源文件......但我认为它应该是目标:源......而不是源:目标......我要发布我在做目的地时得到的回应:来源也是

这是我在运行代码时在终端窗口中得到的响应,正如我在@mario 上面发布的那样

]4

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

这和我的 grunt 版本有什么关系吗?我必须有 4.0 版吗?我有 4.5 .. 它还可以工作吗? 还有许多其他错误...它们中的任何一个都响起为什么我的html没有缩小?感谢任何帮助。提前致谢

【问题讨论】:

  • htmlmin 部分似乎没有做任何事情

标签: gruntjs grunt-contrib-htmlmin


【解决方案1】:

根据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'
            }
        }
    }

希望对你有帮助。

问候。

【讨论】:

  • 为回复欢呼...但已经尝试过但没有成功:(只是再次尝试,但仍然没有缩小我的html
  • 如果在控制台中输入 grunt htmlmin -v 会发生什么?
  • 我认为它的文件{目标:源}不是文件{源:目标}
  • 我应该用我的原始代码还是你推荐的代码试试?你能确认它的来源是:目的地还是目的地来源?当我尝试destion时:源它在运行htmlmin时冻结..
  • 如果您愿意,请两者兼而有之。我的代码是基于文档的,但你的可能也可以。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-15
相关资源
最近更新 更多