twitter-bootstrap Gulp - TypeError:无法分配给 bower / bootstrap.css 的只读属性“cwd”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30412928/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gulp - TypeError: Cannot assign to read only property 'cwd' of bower / bootstrap.css
提问by Karl Taylor
I'm just getting to grips with Gulp.js and this is the only error I can't seem to get around.
我刚刚开始使用 Gulp.js,这是我似乎无法解决的唯一错误。
I have install bootstrap via bower, and I'm trying to minify the bootstrap css.
我已经通过 bower 安装了引导程序,我正在尝试缩小引导程序 css。
Here's my gulp task;
这是我的 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/'));
});
However when I run my main gulp task. It states that the file is "read only"
但是,当我运行我的主要 gulp 任务时。它指出该文件是“只读的”
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)
Things I've tried:
我尝试过的事情:
- Reinstalling bootstrap
- Moving the actual bootstrap.css file to my css file, however it does exactly the same thing.
- 重新安装引导程序
- 将实际的 bootstrap.css 文件移动到我的 css 文件中,但是它做的事情完全一样。
EDIT: SOLVED = To use multiple sources you have to put them in an array.
编辑:已解决 = 要使用多个源,您必须将它们放在一个数组中。
Source: https://github.com/gulpjs/gulp/blob/master/docs/recipes/using-multiple-sources-in-one-task.md
来源:https: //github.com/gulpjs/gulp/blob/master/docs/recipes/using-multiple-sources-in-one-task.md
回答by Karl Taylor
Like @topleft mentioned, it was error in the syntax from using multiple files in my gulp.src. To use multiple sources you need to put them in an array.
就像@topleft 提到的那样,在我的 gulp.src 中使用多个文件的语法错误。要使用多个源,您需要将它们放在一个数组中。
Example:
例子:
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'));
});
回答by llioor
I had this issue when I tried to output 2 css files and I didn't use array [].
当我尝试输出 2 个 css 文件并且我没有使用数组 [] 时,我遇到了这个问题。
Instead of:
代替:
gulp.src('www/css/animate.css', 'www/bower_components/bootstrap/dist/css/bootstrap.css')
.pipe(minifycss({compatibility: 'ie8'}))
.pipe(gulp.dest('www-deploy/css/'));
});
Use this:
用这个:
gulp.src(['www/css/animate.css', 'www/bower_components/bootstrap/dist/css/bootstrap.css'])
.pipe(minifycss({compatibility: 'ie8'}))
.pipe(gulp.dest('www-deploy/css/'));
});
Explanation:
解释:
gulp.src(['./file1.scss', './file2.scss']);
回答by Antonin Cezard
alternatively you could also try with
或者你也可以尝试
return gulp.src('www/**/*.css')
it should add every .css in your directories if thats the wanted effect
如果这是想要的效果,它应该在您的目录中添加每个 .css

