Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gulp-htmlmin hangs...no errors #35

Closed
uberspeck opened this issue Dec 30, 2015 · 12 comments
Closed

gulp-htmlmin hangs...no errors #35

uberspeck opened this issue Dec 30, 2015 · 12 comments

Comments

@uberspeck
Copy link

I just tried switching from gulp-minify-html to gulp-htmlmin. Gulp processing just hangs now. No errors or anything. Anyone have any suggestions?

@jonschlinkert
Copy link
Owner

can you paste your gulpfile here or in a gist?

@uberspeck
Copy link
Author

Thanks for responding! Here's the task that handles my templates (and the rest of my app JS). If i switch back to gulp-minify-html everything runs without a problem...

var gulp = require( "gulp" );
var eventStream = require( "event-stream" );
var concat = require( "gulp-concat" );
var changed = require( "gulp-changed" );
var flatten = require( "gulp-flatten" );
// var minifyHtml = require( "gulp-minify-html" );
var htmlmin = require( "gulp-htmlmin" );
var angularTemplatecache = require( "gulp-angular-templatecache" );
var coffee = require( "gulp-coffee" );
var ngAnnotate = require( "gulp-ng-annotate" );

gulp.task( "appJs", function(cb){

  function _templates(){
    return gulp.src( ["./src/**/*.html"] )
      .pipe( flatten() )
//       .pipe( minifyHtml() )
      .pipe(
        htmlmin({
          collapseWhitespace: true,
          removeComments: true,
          removeAttributeQuotes: true
        })
      )
      .pipe( angularTemplatecache() )
  }

  function _coffeescript(){
    return gulp.src( ["./src/**/*module.coffee", "./src/**/*.coffee"] )
      .pipe( coffee() )
      .pipe( ngAnnotate() )
  }

  return eventStream.merge( _templates(), _coffeescript() )
    .pipe( changed( "./dist/js" ) )
    .pipe( concat( "app.js" ) )
    .pipe( gulp.dest( "./dist/js" ) )

});

and my package.json (maybe a conflict or dependency version issue?)

{
  "...": "...",
  "devDependencies": {
    "coffee-script": "1.10.0",
    "del": "2.2.0",
    "event-stream": "3.3.2",
    "gulp": "3.9.0",
    "gulp-angular-templatecache": "1.8.0",
    "gulp-changed": "1.3.0",
    "gulp-coffee": "2.3.1",
    "gulp-concat": "2.6.0",
    "gulp-cssnano": "2.0.0",
    "gulp-flatten": "0.2.0",
    "gulp-htmlmin": "1.3.0",
    "gulp-minify-html": "1.0.5",
    "gulp-ng-annotate": "1.1.0",
    "gulp-rev": "6.0.1",
    "gulp-rev-collector": "1.0.2",
    "gulp-sass": "2.1.1",
    "gulp-shell": "0.5.1",
    "gulp-strip-comments": "1.1.2",
    "gulp-uglify": "1.5.1",
    "gulp-util": "^3.0.7",
    "gulp-watch": "4.3.5",
    "jasmine-core": "2.3.4",
    "karma-chrome-launcher": "0.2.0",
    "karma-coffee-preprocessor": "0.3.0",
    "karma-jasmine": "0.3.6",
    "karma-ng-html2js-preprocessor": "0.1.2",
    "q": "1.4.1",
    "require-dir": "0.3.0",
    "run-sequence": "1.1.5"
  }
}

@shinnn
Copy link
Collaborator

shinnn commented Jan 4, 2016

@uberspeck Slim down your gulpfile to clarify what is the root cause. Yours includes a lot of code unrelated to this issue.

@ankurk91
Copy link

ankurk91 commented Jan 6, 2016

I am facing the similar issue here.

My package.json

{
"engines": {
    "node": "~0.12.x",
    "npm": "~3.5.x"
  },
  "dependencies": {},
  "devDependencies": {
    "del": "^2.0.2",
    "gulp": "~3.9.0",
    "gulp-angular-templatecache": "^1.8.0",
    "gulp-concat": "^2.5.2",
    "gulp-eslint": "^1.0.0",
    "gulp-htmlhint": "^0.3.0",
    "gulp-htmlmin": "^1.3.0",
    "gulp-if": "~2.0.0",
    "gulp-insert": "^0.5.0",
    "gulp-minify-css": "^1.0.0",
    "gulp-ng-annotate": "^1.1.0",
    "gulp-rev": "^6.0.1",
    "gulp-sourcemaps": "^1.6.0",
    "gulp-strip-debug": "^1.0.2",
    "gulp-uglify": "^1.1.0",
    "gulp-util": "~3.0.6",
    "htmlhint-stylish": "^1.0.3"
  },
  "optionalDependencies": {}
}

My gulpfile.js, complete code

gulp.task('dist:partials', function () {     
        return gulp.src('./public/src/views/**/*.html')        
            .pipe(htmlmin({
                collapseWhitespace: true,
                removeComments: true,
                removeEmptyAttributes: false,
                removeEmptyElements: false
            }))
            .pipe(templateCache({
                filename: 'partials.min.js',
                module: 'angularApp',
                root: 'src/views/',
                standalone: false
            }))           
            .pipe(gulp.dest('./public/dist/js'))      
            .on('error', gutil.log);
    });

My gulp task never ends.
I also tried debugging with gulp-debug and found that it always stuck at a particular file.

public/src/views/_partials/config-condition-question-dialog.html

I also tried to rename file to a shorter name "config-condition-q-d.html" , But no luck .

Another point is that i also tried this plugin in a different project (where i have less number of html files to process) and it worked fine there.

FYI :
I am on Elementary OS 0.3.2 x64 with node v0.12.8 and npm v3.5.3

Let me know how can i help you , thanks.

@eyalzf
Copy link

eyalzf commented Jan 13, 2016

I'm having the same issue as well. It's working just fine for a single file but when my src includes several files the files are minified and output to the dest folder but the task never completes

@jonschlinkert
Copy link
Owner

@Ank91 I don't think this would be caused by the filename. It would be great if you could narrow down what is causing the issue inside the file by removing and re-adding sections. this is probably an issue with htmlmin, but it's hard to say until we know something specific

@ankurk91
Copy link

Found culprit code

<!-- invalid html -->
<input type="text" class="form-control" ng-model="option.grades[grade.grade][gender.id].view_amount" 

name="{{option.option_text + "_" + grade.grade + "_" + gender.id}}" >

The problem was with the invalid html, did you notice double quotes in name attribute value. The correct html should be ->

<!-- valid html -->
<input type="text" class="form-control" ng-model="option.grades[grade.grade][gender.id].view_amount" 

name="{{option.option_text + '_' + grade.grade + '_' + gender.id}}">

So make sure your html code is valid. You can also use w3c-checker

@rscottfree
Copy link

I'm having the same issue with the plugin choking on bad HTML. Obviously I need to fix the HTML, but could we have the plugin ignore bad html or report on the file that is causing it?

The html that it's choking on is the following (notice the missing closing angle bracket):

<md-list-item ng-repeat="item in items | orderBy:item.id"
</md-list-item>

@rscottfree
Copy link

This appears to be a known issue with html-minifier. kangax/html-minifier#332, kangax/html-minifier#177

This issue could probably be closed.

@jonschlinkert
Copy link
Owner

closing based on last comment. thanks

@timothylombrana
Copy link

@rscottfree agreed was able to fix the problem with my syntax error but had I not found this post. I would've struggled with error message.

@mkalish
Copy link

mkalish commented Apr 28, 2016

Same issue for me, but I'm not getting any errors reported back to me? Both referenced issues in the html minifier seem to be resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants