【发布时间】:2014-10-08 16:39:54
【问题描述】:
我需要创建捆绑包,使用 es6 模块编写的应用程序。示例:
import Api from 'api';
function Loader(){
// some code that user api
};
export default Loader;
开发版本通过 gulp-es6-module-transpiler 转换为 AMD 并与 RequireJS 配合使用。 但是我找不到从这里构建捆绑包的方法。 我尝试使用 gulp-es6-module-transpiler 和 gulp-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 不支持乙烯基流,它需要首先使用 CommonJS 模块构建 js 文件,然后使用 Browserify。
也许我理解错了,它可以从一个流构建?还有哪些可能的解决方案?因此,我希望 AMD 用于开发,CommonJS 或 Global 用于生产。
我拥有的应用程序文件结构:
/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
【问题讨论】:
标签: javascript gulp browserify