2

在尝试在构建中执行 html 缩小的 gulp

代码:

gulp.task('html',function(){
  return gulp.src('app/**/*.html')

   .pipe($.useref.assets({searchPath: '{.tmp,app}'}))
   // Concatenate And Minify JavaScript
    .pipe($.if('*.js', $.uglify({
     preserveComments: 'some'
    })))
    // Concatenate And Minify Styles
    .pipe($.if('*.css', $.csso()))
    .pipe($.useref.restore())
    .pipe($.useref())
    // Update Production Style Guide Paths
    .pipe($.replace('styles/main.css'))
    // Minify Any HTML Output Files
    .pipe(gulp.dest'dist'))
    .pipe($.size({title: 'html'}));
});

错误:

TypeError: Uncaught, unspecified "error" event.
    at TypeError (<anonymous>)
    at Transform.emit (events.js:74:15)
    at Transform.onerror (node_modules\gulp\node_modules\vinyl-fs\node_modules\through2\node_modules\readable-stream\lib\_stream_readable.js:558:12)
    at Transform.emit (events.js:95:17)
    at Transform.<anonymous> (index.js:80:42)
    at Array.forEach (native)
    at Transform.<anonymous> (index.js:68:35)
    at Array.for Each (native)
    at Transform.<anonymous> (index.js:46:36)
    at Array.forEach (native)

有没有人遇到过这个问题,请建议如何解决这个问题

谢谢桑达尔

4

1 回答 1

2

升级 gulp-useref:

npm remove gulp-useref && npm i gulp-useref --save-dev
于 2015-04-19T13:25:08.260 回答