Gulp - TypeError: Cannot assign to read only property 'cwd' of bower / bootstrap.css

Gulp - TypeError: Cannot assign to read only property 'cwd' of bower / bootstrap.css

我刚刚开始处理 Gulp.js,这是我似乎无法解决的唯一错误。

我已经通过 bower 安装了 bootstrap,我正在尝试缩小 bootstrap css。

这是我的 gulp 任务;

gulp.task('minifycss', function() {
gulp.src('www/css/animate.css', 'www/bower_components/bootstrap/dist/css/bootstrap.css')
    .pipe(minifycss({compatibility: 'ie8'}))
    .pipe(gulp.dest('www-deploy/css/'));
});

然而,当我 运行 我的主要 gulp 任务时。它指出该文件是 "read only"

Karls-MacBook-Pro:cmp-2015 karltaylor$ gulp
[13:48:50] Using gulpfile ~/Documents/web/cmp-2015/gulpfile.js
[13:48:50] Starting 'sassMin'...
[13:48:50] Finished 'sassMin' after 12 ms
[13:48:50] Starting 'minifycss'...
[13:48:50] 'minifycss' errored after 508 μs
[13:48:50] TypeError: Cannot assign to read only property 'cwd' of www/bower_components/bootstrap/dist/css/bootstrap.css
    at Object.gs.createStream (/Users/karltaylor/Documents/web/cmp-2015/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-stream/index.js:19:46)
    at Object.gs.create (/Users/karltaylor/Documents/web/cmp-2015/node_modules/gulp/node_modules/vinyl-fs/node_modules/glob-stream/index.js:68:42)
    at Gulp.src (/Users/karltaylor/Documents/web/cmp-2015/node_modules/gulp/node_modules/vinyl-fs/lib/src/index.js:33:23)
    at Gulp.<anonymous> (/Users/karltaylor/Documents/web/cmp-2015/gulpfile.js:35:7)
    at module.exports (/Users/karltaylor/Documents/web/cmp-2015/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/Users/karltaylor/Documents/web/cmp-2015/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/Users/karltaylor/Documents/web/cmp-2015/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at /Users/karltaylor/Documents/web/cmp-2015/node_modules/gulp/node_modules/orchestrator/index.js:279:18
    at finish (/Users/karltaylor/Documents/web/cmp-2015/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:21:8)
    at module.exports (/Users/karltaylor/Documents/web/cmp-2015/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:60:3)

我尝试过的事情:

  1. 正在重新安装bootstrap
  2. 将实际的 bootstrap.css 文件移动到我的 css 文件,但它做的事情完全一样。

编辑:已解决=要使用多个源,您必须将它们放在一个数组中。

来源:https://github.com/gulpjs/gulp/blob/master/docs/recipes/using-multiple-sources-in-one-task.md

或者你也可以尝试

return gulp.src('www/**/*.css')

它应该在您的目录中添加每个 .css 如果那是想要的效果

就像@topleft 提到的,在我的 gulp.src 中使用多个文件是语法错误。要使用多个源,您需要将它们放在一个数组中。

示例:

var gulp = require('gulp');
var concat = require('gulp-concat');

gulp.task('default', function() {
    return gulp.src(['foo/*', 'bar/*'])
        .pipe(concat('result.txt'))
        .pipe(gulp.dest('build'));
});

当我尝试输出 2 个 css 文件并且我没有使用数组 [].

时遇到了这个问题

而不是:

gulp.src('www/css/animate.css', 'www/bower_components/bootstrap/dist/css/bootstrap.css')
    .pipe(minifycss({compatibility: 'ie8'}))
    .pipe(gulp.dest('www-deploy/css/'));
});

使用这个:

gulp.src(['www/css/animate.css', 'www/bower_components/bootstrap/dist/css/bootstrap.css'])
    .pipe(minifycss({compatibility: 'ie8'}))
    .pipe(gulp.dest('www-deploy/css/'));
});

解释:

gulp.src(['./file1.scss', './file2.scss']);