Traceur + browserify + uglyify in gulp

I want to have a gulpfile that first transforms my es6 code to es5 and save it to one dir, then browserify it (on every file, not just an entry file) and save it to another dir, lastly I want to minify it and put it in the browserified folder as .min.js files. Here's a diagram of what the result should look like:

src/
  es6/
    index.js
    mod.js
  es5/
    index.js
    mod.js
  es5-browser/
    index.js
    index.min.js
    mod.js
    mod.min.js

Here's my gulpfile so far but I keep getting a can't find module error:

var gulp = require('gulp');
var traceur = require('gulp-traceur');
var browserify = require('gulp-browserify');
var sourcemaps = require('gulp-sourcemaps');

gulp.task('es5ize', function () {
  return gulp.src('src/es6/**/*.js')
    .pipe(sourcemaps.init())
    .pipe(traceur({sourceMaps: true}))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('src/es5'))
    .pipe(browserify({
      debug : true
    }))
    .pipe(gulp.dest('src/es5-browser'))
    ;
});

I know I shouldn't be using gulp-browserify but I wasn't able to get anything like this to work with vinyl either.

It works up until the browserify step

How can I get this to work?

EDIT:

I want to be able to keep this in gulp and not have to exec anything, since I will eventually want to use watchify on this too

All the other examples that are close to this first have browserify create a bundle and then manipulate that bundle but this means that it will always start browserifed which I don't want. They also seem to need to specify an entry file for browserify but I want to specify a glob and have it transform everthing that matches


你需要traceur编译为commonjs模块,这样browserify才能理解.pipe(traceur({modules: 'commonjs' }))

链接地址: http://www.djcxy.com/p/32920.html

上一篇: 如何结合吞咽

下一篇: Traceur + browserify + uglyify一口吞下