2014-10-08 130 views
1

我需要创建捆绑,使用es6模块编写的应用程序。例如:ES6模块+ Gulp

import Api from 'api'; 

function Loader(){ 
    // some code that user api 
}; 

export default Loader; 

通过gulp-es6-module-transpiler开发转换为AMD的版本,并且与RequireJS一起工作良好。 但我找不到从此构建包的方法。 我尝试用一​​口-ES6模块,transpiler和吞掉-browserify:

gulp.task('build_js', function() { 
    gulp.src('app/**/*.jsx') 
    .pipe(gulp_react({errLogToConsole: true})) 
    .pipe(transpiler({ 
     type: 'cjs' 
    })) 
    .pipe(gulp.dest('./' + build_fld + '/')); 
}); 

gulp.task('brow', ['build_js'] function(){ 
    gulp.src('dist/auto-name.js') 
    .pipe(browserify()) 
    .pipe(gulp.dest('./' + build_fld + '/')); 
}); 

但我有错误,从Browserify:

Error: module 'name' not found from 'd:\\Work\\lib.react-suggest\\dist\\fake_32525252.js'; 

但通常是不错的方法,因为据我所知browserify不支持vinyl流,并且它需要首先使用CommonJS模块构建js文件,然后使用Browserify。

也许我理解错了什么,它可以从一个流构建?还有什么其他的解决方案?因为我希望AMD用于开发,CommonJS或Global用于生产。

应用程序文件stucture我有什么:

/app 
    -app.jsx 
    -component1.jsx 
    -component2.jsx 
    -index.html 
/.tmp 
/dist 
gulpfile.js 

在结果我想:

/app 
    -app.jsx 
    -component1.jsx 
    -component2.jsx 
    -index.html 
/.tmp 
    -app.js 
    -component1.js 
    -component2.js 
    -index.html 
/dist 
    -app.min.js 
gulpfile.js 

回答

0

据我所知,Browserify并在添加/需要接受法流。我不确定口袋呼叫是否会产生真正的流。然而坦率地说,当你可以直接调用browserify api来产生结果时,为什么会在那里使用gulp呢?

var b = browserify(); 
b.add('dist/auto-name.js'); 
b.bundle().pipe(gulp.dest('./' + build_fld + '/')); 

除非你正在用Gulp做一些其他的魔法,你没有在这里显示。在那种情况下,祝你好运:)