2017-04-11 86 views
0

我試圖(在測試意思應用程序中;使用:angular2,webpack-stream + gulp,express/consign,babel-node/gulp)transpile es6將服務器應用程序的文件格式化爲wwwroot(dist),以便維持應用程序的文件/路徑結構(因此,dummy ...pipe(dist)不起作用,因爲輸出文件會變平坦)。 這裏是代碼:Babel-transpile將應用程序文件轉換爲dist,保存路徑的結構

... merged = require('merge-stream')(),..... 

gulp.task('compile', ['clean:wwwroot'],() => { 
    gulpEnv.set({ 
    NODE_ENV: 'production', 
    ENV: 'prod' 
    }); 
    let appFilesPaths = ['./app.js', './utils', './routes', './db.js', './boot.js', './models']; 
    let streams = []; 

    let compileAppFile(file, rel = './') => { 
    log('[compile]:Rel ::: ', rel) 
    let fullPath = path.join(__dirname, file); 
    let fullDestPath = path.join(paths.appDist, rel); 
    log('[compile:::full_Path]', fullPath); 
    log('[compile:::full_Dest]', fullDestPath) 

    let stream = gulp.src(fullPath) 
     .pipe(babel()) 
     .pipe(debug({ 
     title: 'Gulp-Debug' 
     })) 
     .pipe(gulp.dest(fullDestPath)) 
     .on('finish',() => { log('DONE') }) 
     .on('error', (err) => { log('[compile error]', err) }); 

    merged.add(stream) 
     .pipe(debug({ 
     title: `[Debug::MergedStreams]::: ${stream}` 
     })); 
    } 

    let traverseAppPaths(fsEntity, rel = './') => { 
    log('[traverse]:Rel ::: ', rel) 
    let fullPath = path.resolve(rel, fsEntity); 
    fs.stat(fullPath, (err, stats) => { 
     if (err) throw new Error(`Error reading app file : \n ${err}`); 
     if (stats.isFile()) { 
     log('[traverse:::fsEntity]', fsEntity) 
     if (fsEntity.indexOf('js') !== -1) 
      compileAppFile(fsEntity, rel); 
     } else { 
     fs.readdir(fsEntity, (err, files) => { 
      if (err) throw new Error(`Error reading app directory's files : ${err}`); 
      files.filter(item => item.indexOf('js') !== -1) 
      .forEach(item => traverseAppPaths(item, fsEntity)); 
     }) 
     } 
    }) 
    } 

    appFilesPaths.forEach(fsItem => traverseAppPaths(fsItem)); 
    return merged 
    .pipe(debug({ 
     title: '[merged_streams]:::' 
    })); 

}); 
gulp.task('test', ['compile']); 

。但它otputs只有3個文件wwwroot:transpiled app.jsboot.jsdb.js(即,像utils沒有路徑..編譯/感動印度wwwroot


PS還有使用webpack/babel-loader的問題gist

回答