我需要创建捆绑,使用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