Search code examples
javascriptnode.jsgulpbabeljsglob

Not able to run simple babel from src folder to dist


I use the following code for babel transpile of code. My app is built like following

-src
 -- bin
   ---www
 -- routes
   ---index1.js
   ---index2.js
 -- config.json
-package.json 

Now I want that all this file will be transpiled to the dist folder

I use the following gulp

gulp.task('es6', () => {
    return gulp.src(['src/**/*.js','./src/**/www','./src/**/*.json'])
        .pipe(babel({
            presets: ['es2015']
        }))
        .pipe(gulp.dest('dist'));
});

This create new dist of dist like following but without the config.json file,why ?

-dist
 -- bin
   ---www
 -- routes
   ---index1.js
   ---index2.js

and when I run the gulp file I got error Cannot find module '../config.json' ,any idea how to solve it ?

I struggle with it almost 3 days, I think I miss something basic here...:( This is the project example ,you can do npm install and run gulp to see the error...

https://drive.google.com/open?id=0B8fd7J9aXGXaQng1ZFJkU2Z4OUk


Solution

  • Download and it seems only an issue with babel-gulp which doesn't recognize the .json

    edited like this and it works

    gulp.task('es6', () => {
        return gulp.src(['./src/**/*.js','./src/**/www'])
            .pipe(babel({
                presets: ['es2015']
            }))
            .pipe(gulp.dest('dist'));
    });
    
    gulp.task('json', () => {
        return gulp.src(['./src/*.json'])
            .pipe(gulp.dest('dist'))
    })
    

    and then

    gulp.task('default', [ 'es6', 'json', 'nodemon'], () => {
        console.log("Done");
    });