ericclemmons / grunt-angular-templates

Grunt build task to concatenate & pre-load your AngularJS templates
MIT License
710 stars 107 forks source link

Error message when giving htmlmin options #99

Closed vberistain-xx closed 10 years ago

vberistain-xx commented 10 years ago

Everything is working very nice but I can't get my templates minified. If i fill 'htmlmin' option with arguments grunt is giving me this warning "Cannot call method 'replace' of undefined Use --force to continue" and grunt stops.

This is my Gruntfile

ngtemplates: {
      app: {
        cwd: 'app',
        src: 'scripts/directives/**/**.html',
        dest: '.tmp/templates.js',
        options: {
          prefix: '/',
          module: 'MoApp',
          htmlmin: {
            collapseBooleanAttributes:      true,
            collapseWhitespace:             true,
            removeAttributeQuotes:          true,
            removeEmptyAttributes:          true,
            removeRedundantAttributes:      true,
            removeScriptTypeAttributes:     true,
            removeStyleLinkTypeAttributes:  true
          }
        }
      }
    }

Any idea what am I doing wrong? Thanks in advance.

ericclemmons commented 10 years ago

Shoot, there's no line-number or anything? Try it with grunt --debug or grunt --verbose (I forget which). Otherwise, I'll just re-use your example code :)

vberistain-xx commented 10 years ago

Hi! Thanks for your quick reply. I realised that probably is a htmlmin issue since some of my html views (html files) are also throwing this error. Are you aware of any incompatibility between angularjs and htmlmin?

This works:

        <section class="l-swiper-col">
            <h1 class="swiper-col-header hidden-xs hidden-sm">{{ 'YESTERDAY' | translate }}</h1>
            <one-match-live-scores  date="dates.yesterday"></one-match-live-scores>
        </section>

This doesn't:

        <section class="l-swiper-col">
            <h1 class="swiper-col-header hidden-xs hidden-sm">{{ 'YESTERDAY' | translate }}</h1>
            <div one-match-live-scores  date="dates.yesterday"></div>
        </section>

So if i insert a directive as an element is ok but not as an argument. Thanks a lot!

ericclemmons commented 10 years ago

The thing that sucks about htmlmin is that the parser just isn't that great. I'd recommend stripping primarily whitespace with it, but avoiding getting that last 2% because of errors it creates.

At the end of the day, there's almost always more bandwidth lost due to CSS, premature loading of JS, or images!

vberistain-xx commented 10 years ago

Thanks a lot for your help Eric!