Uglify上的Gulp流错误

时间:2014-10-02 08:15:14

标签: node.js gulp uglifyjs

我第一次写了一个gulp脚本,我很难根据gulp uglify我的JS文件 - 如果,我确实认为我的代码是正确的:

var gulp = require('gulp');
var gutil = require('gulp-util');
var gulpif = require('gulp-if');
var concat = require('gulp-concat');
var del = require('del');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var minifyCSS = require('gulp-minify-css');
var watch = require("gulp-watch");
var argv = require('yargs').argv;

var paths = {
  styles: ['css/maaap.css'],
  stylesUfe: ['css/ufe.css'],
  scripts: ['js/lang.js', 'js/bootstrap.js', 'js/jquery.js', 'js/leaflet.js', 'js/emm.js', 'js/markercluster.js', 'js/moment.js', 'js/geolocate.js'],
  scriptsUfe: ['js/ufe.js', 'js/exif.js', 'js/binaryajax.js', 'js/canvasResize.js']
};

// Not all tasks need to use streams
// A gulpfile is just another node program and you can use all packages available on npm
gulp.task('clean', function(cb) {
  console.log(cb);
  del(['build'], cb);
});

// Merge all the css files from paths.styles then move it to build/css/style.css
// If you append --ufe you also merge the files from paths.stylesUfe
// If you append --prod your file become build/css/style.min.css and is compressed
gulp.task('styles', ['clean'], function() {
  var source = (!argv.ufe) ? paths.styles : paths.styles.concat(paths.stylesUfe);
  return gulp.src(source)
    .pipe(concat('style.min.css'))
    .pipe(gulpif(argv.prod, minifyCSS()))
    .pipe(gulp.dest('build/css'));
});

// Merge all the css js files from paths.scripts then move it to build/js/livemap.js
// If you append --ufe you also merge the files from paths.scriptsUfe
// If you append --prof your file become build/js/livemap.min.js and is compressed
gulp.task('scripts', function() {
  var source = (!argv.ufe) ? paths.scripts : paths.scripts.concat(paths.scriptsUfe);
  return gulp.src(source)
    .pipe(concat('livemap.min.js'))
    .pipe(gulpif(argv.prod, uglify()))
    .pipe(gulp.dest('build/js'))
});

gulp.task('watch', function() {
  watch({glob: 'js/**/*.js'}, function (files) {
      gulp.start('scripts'); // run the compile task
  });
  watch({glob: 'css/*.css'}, function (files) {
      gulp.start('styles'); // run the compile task
  });
});


// The default task (called when you run `gulp` from cli)
gulp.task('default', ['scripts', 'styles']);

我在控制台中收到的错误日志对我来说很奇怪:

stream.js:94
      throw er; // Unhandled stream error in pipe.
            ^
Error
    at new JS_Parse_Error (/home/soueuls/Projects/MAAAP/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:189:18)
    at js_error (/home/soueuls/Projects/MAAAP/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:197:11)
    at croak (/home/soueuls/Projects/MAAAP/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:656:9)
    at token_error (/home/soueuls/Projects/MAAAP/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:664:9)
    at unexpected (/home/soueuls/Projects/MAAAP/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:670:9)
    at expr_atom (/home/soueuls/Projects/MAAAP/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1154:13)
    at maybe_unary (/home/soueuls/Projects/MAAAP/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1327:19)
    at expr_op (/home/soueuls/Projects/MAAAP/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1349:33)
    at expr_ops (/home/soueuls/Projects/MAAAP/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1362:16)
    at maybe_conditional (/home/soueuls/Projects/MAAAP/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1367:20)
    at maybe_assign (/home/soueuls/Projects/MAAAP/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1391:20)
    at expression (/home/soueuls/Projects/MAAAP/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1410:20)
    at expr_list (/home/soueuls/Projects/MAAAP/node_modules/gulp-uglify/node_modules/uglify-js/lib/parse.js:1177:24)

有什么想法吗?

0 个答案:

没有答案