gulp错误:TypeError:无效的非字符串/缓冲区块

时间:2016-07-13 18:32:19

标签: gulp browserify

我正在尝试使用gulp自动执行某些任务。

这是一个vue.js项目,我正在使用以下工具:

  • browserify
  • vueify
  • vuemaker

我收到此错误:

PS C:\mycode\myfrontend\myvuemaker> .\node_modules\.bin\gulp
[14:20:57] Using gulpfile C:\mycode\myfrontend\myvuemaker\gulpfile.js
[14:20:57] Starting 'default'...
[14:20:57] 'default' errored after 39 ms
[14:20:57] TypeError: Invalid non-string/buffer chunk
    at validChunk (_stream_writable.js:185:14)
    at WriteStream.Writable.write (_stream_writable.js:212:12)
    at DestroyableTransform.ondata (stream.js:31:26)
    at emitOne (events.js:77:13)
    at DestroyableTransform.emit (events.js:169:7)
    at DestroyableTransform.<anonymous> (C:\mycode\myfrontend\myvuemaker\node_modules\gulp\node_modules\vinyl-fs\node_mo
dules\through2\node_modules\readable-stream\lib\_stream_readable.js:786:14)
    at emitNone (events.js:67:13)
    at DestroyableTransform.emit (events.js:166:7)
    at emitReadable_ (C:\mycode\myfrontend\myvuemaker\node_modules\gulp\node_modules\vinyl-fs\node_modules\through2\node
_modules\readable-stream\lib\_stream_readable.js:448:10)
    at emitReadable (C:\mycode\myfrontend\myvuemaker\node_modules\gulp\node_modules\vinyl-fs\node_modules\through2\node_
modules\readable-stream\lib\_stream_readable.js:444:5)

这是我的package.json

{
  "name": "myvuemaker",
  "version": "1.0.0",
  "description": "using vuemaker browserify vueify and gulp",
  "main": "gulpfile.js",
  "dependencies": {
    "babel-core": "^6.10.4",
    "babel-preset-es2015": "^6.9.0",
    "browserify": "^13.0.1",
    "babel-runtime": "^6.9.2",
    "gulp": "^3.9.1",
    "gulp-vuemaker": "^1.0.1",
    "babel-plugin-transform-runtime": "^6.9.0",
    "vue": "^1.0.26",
    "vueify": "^8.7.0",
    "vue-hot-reload-api": "^2.0.5"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

此命令正常

 .\node_modules\.bin\browserify -t vueify -e .\mainvue.js -o .\build\bundle.js

但我想自动化它。

由于

1 个答案:

答案 0 :(得分:0)

以下是我找到的解决方案:

gulp = require('gulp');
var vuemaker = require('gulp-vuemaker');
var fs = require("fs")
var browserify = require('browserify')
var vueify = require('vueify')

gulp.task('componentise', function() {
    return gulp.src('./lib/**/*.+(js|css|html)')
        .pipe(vuemaker())
        .pipe(gulp.dest('./components/'))
});

gulp.task('browserise', function(){
    console.log("browserifying ...");
    browserify('./mainvue.js')
        .transform(vueify)
        .bundle()
        .pipe(fs.createWriteStream("build/bundle.js"))
});

gulp.task('default', ['componentise', 'browserise']);

有没有更好的解决方案(我是新来的)?