简体   繁体   中英

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

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");
});
'./src/**/*.json'

但是您的配置文件是src的直接子级,因此您应该执行以下操作:

'./src/*.json'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM