Browserify fails to create bundle with babelify transform (TypeError: Path must be a string.)

杀马特。学长 韩版系。学妹 提交于 2019-12-04 03:25:39

That error is because you need a vinyl-source-stream in there. The result of .bundle() is a standard Node stream of file data. You are taking that data are passing it to rename which expects a stream of Gulp File objects.

var source = require('vinyl-source-stream');

// stuff

  function rebundle(bundle) {
    return bundle.bundle()
    .on('error', function(error) {
      console.log(error.stack, error.message);
      this.emit('end');
    })
    .pipe(
        gulpif(
          (process.env.NODE_ENV == 'production'),

          // Use 'source' here instead, which converts binary
          // streams to file streams.
          source('bundle.min.js'),
          source('bundle.js')
        )
    )
    .pipe(gulpif((process.env.NODE_ENV == 'production'), buffer()))
    .pipe(gulpif((process.env.NODE_ENV == 'production'), uglify()))
    .pipe(gulp.dest('dist/js'));
  }

Instead of using rename, you can use source to define the initial name of the file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!