0

I am using babel to create my gulpfile.babel.js

I am using this code to dynamically include the modules and importing tasks it was working in babel 5.8.x but after upgrading to 6.3.x it stop working

I am not being able to figure out which plugin i am missing please help. Please assume the code below does not contains typo error.

I am using

"babel-preset-es2015": "^6.3.13" 
"gulp-babel": "^6.1.1"

.babelrc content

{
  "presets": ["es2015"]
}

gulp:

import gulp from "gulp";
import del from "del";
import { default as runSequence} from "run-sequence";

let basePath = "modules/";
['filename1', 'filename2'].forEach((moduleName) => {
    require(`./${basePath}${moduleName}`).apply(this, [gulp, runSequence, del]);
});

// Tasks are defined in the modules 'required' above

my filenameX.js file look like this

export default function(gulp, runSequence, del) {
    gulp.task("clean", del.bind(null, ["./temp/"]));
}
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Aamir Shah
  • 646
  • 5
  • 14

1 Answers1

0

The default require functionality can be achieved in babel 6.3.x by using

['filename1', 'filename2'].forEach((moduleName) => {
    require(`./${basePath}${moduleName}`).default.apply(this, [gulp, runSequence, del]);
});

Babel 6.x has dropped some of the CommonJS interop behavior and ES6 modules transpiled to ES5 will now have their default exposed as .default.

Reference file https://phabricator.babeljs.io/T2683

Aamir Shah
  • 646
  • 5
  • 14
  • This has also been covered in http://stackoverflow.com/questions/33505992/babel-6-changes-how-it-exports-default. – loganfsmyth Dec 24 '15 at 19:20