Babel-transile将app文件表达/发送到dist,保留路径'结构体

时间:2017-04-11 13:00:41

标签: node.js webpack gulp ecmascript-6 babel

我试图(在测试中使用:使用:angular2,webpack-stream + gulp,express / consign,babel-node / gulp)将服务器app的es6模块化文件转换为wwwroot(dist)forlder持续应用程序的文件' /路径'结构(因此,虚拟...pipe(dist)不起作用,因为将输出文件展平为dist in line); 这是代码:

... 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']);

但是......它只输出3个文件到wwwroot:已编译app.jsboot.jsdb.js(即没有像utils这样的路径。编译/移动indo wwwroot

P.S还有使用webpack / babel-loader gist

的问题

1 个答案:

答案 0 :(得分:0)

..呃,像往常一样:路径(我做过)不匹配: https://github.com/VovanSuper/MEAN-dummy/blob/master/gulpfile.js#L62

PS。仍然希望基于webpack(+ babel-loader)的方式