2017-03-08 116 views
2

我得到這個錯誤,讓我抓狂不已:GulpUglifyError:無法縮小JavaScript

events.js:154 
     throw er; // Unhandled 'error' event 
    ^
GulpUglifyError: unable to minify JavaScript 
    at createError (/Users/berretan/Documents/Projects/promo-brochure/node_modules/gulp-uglify/lib/create-error.js:6:14) 
    at wrapper (/Users/berretan/Documents/Projects/promo-brochure/node_modules/gulp-uglify/node_modules/lodash/_createHybrid.js:87:15) 
    at trycatch (/Users/berretan/Documents/Projects/promo-brochure/node_modules/gulp-uglify/minifier.js:26:12) 
    at DestroyableTransform.minify [as _transform] (/Users/berretan/Documents/Projects/promo-brochure/node_modules/gulp-uglify/minifier.js:76:19) 
    at DestroyableTransform.Transform._read (/Users/berretan/Documents/Projects/promo-brochure/node_modules/readable-stream/lib/_stream_transform.js:159:10) 
    at DestroyableTransform.Transform._write (/Users/berretan/Documents/Projects/promo-brochure/node_modules/readable-stream/lib/_stream_transform.js:147:83) 
    at doWrite (/Users/berretan/Documents/Projects/promo-brochure/node_modules/readable-stream/lib/_stream_writable.js:347:64) 
    at writeOrBuffer (/Users/berretan/Documents/Projects/promo-brochure/node_modules/readable-stream/lib/_stream_writable.js:336:5) 
    at DestroyableTransform.Writable.write (/Users/berretan/Documents/Projects/promo-brochure/node_modules/readable-stream/lib/_stream_writable.js:274:11) 
    at DestroyableTransform.ondata (/Users/berretan/Documents/Projects/promo-brochure/node_modules/readable-stream/lib/_stream_readable.js:546:20) 

我不知道哪裏出錯的來源。但在我的文件夾結構看:

enter image description here

現在:我有這樣的這4個文件:

<script src="assets/scripts/vendor/siteconfig.js"></script> 
<script src="assets/scripts/vendor/responsive-tags.js"></script> 
<script src="assets/scripts/vendor/tealium-video.js"></script> 
<script src="assets/scripts/vendor/tealium.js"></script> 

而在HTML引用的這些塊:

enter image description here

您可能會看到有2個參考塊。如果我將這4個文件放在這些塊之外,當我運行gulp build時,一切都很順利,但在實時環境中,我在這些文件上獲得了404。但是如果我把這些文件放在這兩個引用塊中,我會得到上面提到的錯誤。

這是我一飲而盡congif的一部分:

//Require specific modules 
var gulp = require('gulp'); 
var del = require('del'); 
var get = require('get-value'); 
var $ = require('gulp-load-plugins')(); 
var multimatch = require('multimatch'); 
var bs = require("browser-sync").create(); 
var assemble = require('assemble'); 
var app = assemble(); 
var guppy = require('git-guppy')(gulp); 
var gutil = require('gulp-util'); 
var watch = require('gulp-watch'); 
var helpers = require('handlebars-helpers')(); 
var runSequence = require('run-sequence'); 

gulp.task('captions:dist', function() { 
    gulp.src('app/assets/captions/**/*') 
    .pipe(gulp.dest('dist/assets/captions')); 
}); 

//Copy Task for assets that needs to be moved to /dist on build task 
gulp.task('copy:vendorjs', ['clean:dist'], function(){ 
    return gulp.src(['app/assets/scripts/vendor/jquery-2.1.4.min.js']) 
     .pipe(gulp.dest('dist/assets/scripts/vendor')); 
}); 

//Lint task 
gulp.task('eslint', function() { 
    return gulp.src(['app/{assets,components,pages}/**/*.js', '!app/assets/scripts/vendor/**']) 
    .pipe($.eslint()) 
    .pipe($.eslint.format()) 
    .pipe($.eslint.failAfterError()); 
}); 

gulp.task('pre-commit', function() { 

    var filterVendorJs = ['app/**/*.js', '!app/assets/scripts/vendor/*']; 
    var filesToTest = multimatch(guppy.src('pre-commit'), filterVendorJs); 

    return gulp.src(filesToTest) 
    .pipe($.plumber()) 
    .pipe($.eslint({ rulePaths: ['/'], configFile: '.eslintrc'})) 
    .pipe($.eslint.format()) 
    .pipe($.eslint.failAfterError()); 
}); 

//Assemble load task 
gulp.task('load', function(cb) { 

    //Set main assemble options 
    app.option('layout', 'default'); 
    app.layouts('app/layouts/*.hbs'); 
    app.pages('app/pages/**/*.hbs'); 
    app.partials('app/components/**/*.hbs'); 
    app.engine('hbs', require('engine-handlebars')); 
    app.data(['app/{pages,components,data}/**/*.json']); 

    cb(); 
}); 

//Assemble main task 
gulp.task('assemble', ['load'], function(){ 
    return app.toStream('pages') 
     .pipe(app.renderFile()) 
     .pipe($.extname()) 
     .pipe($.flatten()) 
     .pipe($.plumber()) 
     .pipe(app.dest('.tmp')); 
}); 

gulp.task('assemble:dist', ['load', 'clean:dist'], function(){ 
    return app.toStream('pages') 
     .pipe(app.renderFile()) 
     .pipe($.extname()) 
     .pipe($.flatten()) 
     .pipe($.plumber()) 
     .pipe(app.dest('dist')); 
}); 

gulp.task('usemin', ['assemble:dist', 'sass:dist'], function() { 
    return gulp.src('dist/**/*.html') 
    .pipe($.foreach(function (stream) { 
     return stream 
     .pipe($.plumber()) 
     .pipe($.usemin({ 
      cssvendor: [$.cssnano()], 
      css: [$.cssnano()], 
      jsvendor: [$.uglify()], 
      js: [$.uglify()] 
     })) 
     .pipe(gulp.dest('dist/')); 
    })); 

}); 

//Serve the site from .tmp directory 
gulp.task('default', ['assemble', 'sass', 'fonts', 'notify:server'], function(){ 

    var globs = [ 
     '.tmp/**/*.html', 
     '.tmp/assets/styles/{,*/}*.css', 
     '.tmp/assets/**/*.js', 
     'app/assets/images/{,*/}*.*' 
    ]; 
}); 


//Serve the site from the dist directory 
gulp.task('default:dist', function(){ 
    bs.init({ 
    notify: false, 
    port: 9000, 
    server: { 
     baseDir: ['dist'] 
    } 
    }); 
}); 

gulp.task('build', ['sass:dist', 'usemin', 'images', 'fonts:dist', 'copy:vendorjs','captions:dist'], function(){ 
}); 

任何建議?

回答

-1

可能你在JavaScript文件中有語法錯誤。例如用jslint.com檢查它。

+0

這不是一個答案。 –