gulp build error - event.js上未处理的事件

时间:2016-05-30 16:29:24

标签: angularjs node.js gulp

我一直在做gulp-angular项目。

执行gulp build时出现此错误。

有关此错误的任何想法或找到确切的错误。

[12:19:30]开始' html' ...

[12:19:30] gulp-injection 1个文件到index.html。

[12:19:36] dist / maps / styles / app-a0aea5096b.css.map 237.42 kB

[12:19:37] dist / maps / styles / vendor-7ddea9127c.css.map 59.83 kB

events.js:141       扔掉//未处理的错误'事件       ^

错误:脚本/ vendor-cd3b0d9620.js:错误:由于解析错误而无法处理源 '进口'和'出口'可能只出现在' sourceType:module' (87672:0)

我的gulp构建文件如下所示



'use strict';

var path = require('path');
var gulp = require('gulp');
var conf = require('./conf');
var lazypipe = require('lazypipe');
var gulpif = require('gulp-if');
var $ = require('gulp-load-plugins')({
  pattern: ['gulp-*', 'main-bower-files', 'uglify-save-license', 'del']
});

gulp.task('partials', function () {
  return gulp.src([
    path.join(conf.paths.src, '/app/**/*.html'),
    path.join(conf.paths.tmp, '/serve/app/**/*.html')
  ])
    .pipe($.minifyHtml({
      empty: true,
      spare: true,
      quotes: true
    }))
    .pipe($.angularTemplatecache('templateCacheHtml.js', {
      module: 'sleepyfish',
      root: 'app'
    }))
    .pipe(gulp.dest(conf.paths.tmp + '/partials/'));
});

gulp.task('html', ['inject', 'partials'], function () {
  var partialsInjectFile = gulp.src(path.join(conf.paths.tmp, '/partials/templateCacheHtml.js'), {read: false});
  var partialsInjectOptions = {
    starttag: '<!-- inject:partials -->',
    ignorePath: path.join(conf.paths.tmp, '/partials'),
    addRootSlash: false
  };


  // Building lazypipe for replacing image path in css
  var _c = null;

  function condition(file) {
    _c = file.path;
    //return _c.indexOf('bower_components') > -1 && _c.indexOf('.css') > -1;
    return _c.indexOf('.css') > -1;
  }

  var cssPathReplacement = lazypipe()
    .pipe(function () {
      return gulpif(condition, $.replace(/url\([^\)]+\.(png|jpg|jpeg|gif)('|"?)\)/g, function (match) {
        var url = match.match(/[\.\/\w\-\_]+/g)[1];
        var imgName = path.basename(url);
        var prepend = '../assets/img';
        try {
          var prepostpand = path.dirname(_c)
            .match(/bower_components\/[^\/]+/g)[0]
            .replace('bower_components/', '/');
          return 'url(' + prepend + prepostpand + '/' + imgName + ')';
        } catch (e) {
            var replaceWith = '../assets/';
            if (url.indexOf('../assets') > -1) replaceWith = '../';

            return 'url(' + url.replace('../', replaceWith) + ')';
        }

      }));
    });


  var htmlFilter = $.filter('*.html', {restore: true});
  var jsFilter = $.filter('**/*.js', {restore: true});
  var cssFilter = $.filter('**/*.css', {restore: true});
  var assets;

  return gulp.src(path.join(conf.paths.tmp, '/serve/*.html'))
    .pipe($.inject(partialsInjectFile, partialsInjectOptions))
    .pipe(assets = $.useref.assets({}, cssPathReplacement))
    .pipe($.rev())
    .pipe(jsFilter)
    .pipe($.sourcemaps.init())
    .pipe($.ngAnnotate())
    .pipe($.uglify({preserveComments: $.uglifySaveLicense})).on('error', conf.errorHandler('Uglify'))
    .pipe($.sourcemaps.write('maps'))
    .pipe(jsFilter.restore)
    .pipe(cssFilter)
    .pipe($.sourcemaps.init())
    .pipe($.replace('../../bower_components/bootstrap-sass/assets/fonts/bootstrap/', '../fonts/'))
    .pipe($.minifyCss({processImport: false}))
    .pipe($.sourcemaps.write('maps'))
    .pipe(cssFilter.restore)
    .pipe(assets.restore())
    .pipe($.useref())
    .pipe($.revReplace())
    .pipe(htmlFilter)
    .pipe($.minifyHtml({
      empty: true,
      spare: true,
      quotes: true,
      conditionals: true
    }))
    .pipe(htmlFilter.restore)
    .pipe(gulp.dest(path.join(conf.paths.dist, '/')))
    .pipe($.size({title: path.join(conf.paths.dist, '/'), showFiles: true}));
});

// Only applies for fonts from bower dependencies
// Custom fonts are handled by the "other" task
gulp.task('fonts', function () {
  return gulp.src($.mainBowerFiles())
    .pipe($.filter('**/*.{eot,svg,ttf,woff,woff2}'))
    .pipe($.flatten())
    .pipe(gulp.dest(path.join(conf.paths.dist, '/fonts/')));
});

// -- Custom task: Copy bower images to img dir
gulp.task('images', function () {
  return gulp.src($.mainBowerFiles())
    .pipe($.filter('**/*.{png,jpg,jpeg,gif}'))
    .pipe(gulp.dest(function (file) {
      var dst = file.base.match(/bower_components\/([^\/]+)/g)[0].replace('bower_components', '');
      return path.join(conf.paths.dist, '/assets/img' + dst);
      //
    }));
});


gulp.task('other', function () {
  var fileFilter = $.filter(function (file) {
    return file.stat.isFile();
  });

  return gulp.src([
    path.join(conf.paths.src, '/**/*'),
    path.join('!' + conf.paths.src, '/**/*.{html,css,js,scss}')
  ])
    .pipe(fileFilter)
    .pipe(gulp.dest(path.join(conf.paths.dist, '/')));
});

gulp.task('clean', function () {
  return $.del([path.join(conf.paths.dist, '/'), path.join(conf.paths.tmp, '/')]);
});

gulp.task('build', ['html', 'fonts', 'images', 'other']);
&#13;
&#13;
&#13;

0 个答案:

没有答案