K
K
keslo2015-11-17 21:23:07
JavaScript
keslo, 2015-11-17 21:23:07

Handling es2015 in gulp?

Good afternoon.
I understand gulp.
Understood with a simple assembly. I don’t understand how to set up translation from es2015 to es5.
I want to use native import-export from es2015, but I don't understand how to build a working js file?
Here is what is issued:

module.js:339
    throw err;
    ^

Error: Cannot find module './index'

The code itself:
/*
Структура

/
- public/
-- bundle.js
- js/
-- index.js
-- main.js

*/

// index.js
export let a = 1;

// main.js
import one from './index';
console.log(one);

// gulpfile.js
var gulp = require('gulp');
var notify = require('gulp-notify');
var concat = require('gulp-concat');
var babel = require('gulp-babel');

gulp.task('default', function() {
  gulp.src('js/*.js')
    .pipe(concat('bundle.js'))
    .pipe(babel({
      presets: ['es2015']
    }))
    .pipe(gulp.dest('public'))
    .pipe(notify('Done!'));
});

gulp.task('watch', function() {
  gulp.watch('js/*.js', ['default'])
});

// итоговая сборка
'use strict';
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.a = undefined;
var _index = require('./index');
var _index2 = _interopRequireDefault(_index);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var a = exports.a = 1;
console.log(_index2.default);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yaroslav Lyzlov, 2015-11-17
@dixoNich

https://github.com/babel/gulp-babel
First link in google.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question