ES6编译控制台错误

时间:2017-05-23 14:35:37

标签: ecmascript-6 gulp

我有以下gulp文件:

'use strict'

const gulp = require('gulp');
const babel = require('gulp-babel');
const concat = require('gulp-concat');


// Create an es6 task
gulp.task('es6', () => {
    // Return gulp.src with the src set to our src folder
    // we return here do that we indicate to gulp that this task is async
    return gulp.src('src/*.js')
        // We pipe the source into babel
        .pipe(babel({
            // We need to tell babel to use the babel-preset-es2015
            presets: ['es2015']
        }))
        // We then pipe that into gulp.dest to set a final destination
        // In this case a build folder
        .pipe(concat('app.js'))
        .pipe(gulp.dest('build'));
});

gulp.task('default', ['es6'],() => {
    gulp.watch('src/*.js',['es6'])
});

当我运行gulp它正确编译没有错误,但是我在控制台中得到这个错误预览HTML:

Uncaught ReferenceError: exports is not defined

指的是:

Object.defineProperty(exports, "__esModule", {
  value: true
});

如何解决这个问题?

已更新

我已更新了我的gulp文件,但它还没有完成工作:

'use strict'

const gulp = require('gulp');
const babel = require('gulp-babel');
const gutil = require('gulp-util');
const source = require('vinyl-source-stream');
const browserify = require('browserify');

// Create an es6 task
gulp.task('es6', () => {
    // Return gulp.src with the src set to our src folder
    // we return here do that we indicate to gulp that this task is async
    // return gulp.src('src/*.js')
    //  // We pipe the source into babel
    //  .pipe(babel({
    //      // We need to tell babel to use the babel-preset-es2015
    //      presets: ['es2015']
    //  }))
    //  // We then pipe that into gulp.dest to set a final destination
    //  // In this case a build folder
    //  .pipe(concat('src/*.js'))
    //  .pipe(gulp.dest('build'));

    return browserify('src/app.js')
        .bundle()
        .pipe(source('bulid/app.js'))
        .pipe(babel({
            // We need to tell babel to use the babel-preset-es2015
            presets: ['es2015']
        }))
        .pipe(gulp.dest('build'));
});

gulp.task('default', ['es6'],() => {
    gulp.watch('src/*.js',['es6'])
});

0 个答案:

没有答案