2015-05-23 21 views
22

Tôi chỉ bắt tay với Gulp.js và đây là lỗi duy nhất mà tôi không thể có được.Gulp - TypeError: Không thể gán cho chỉ đọc thuộc tính 'cwd' của bower/bootstrap.css

Tôi đã cài đặt trình khởi động qua bower và tôi đang cố gắng rút gọn css bootstrap.

Đây là nhiệm vụ nuốt chửng của tôi;

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/')); 
}); 

Tuy nhiên, khi tôi chạy tác vụ chính của gulp. Nó nói rằng các tập tin được "chỉ đọc"

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) 

Những điều tôi đã cố gắng:

  1. Cài đặt lại bootstrap
  2. Di chuyển các tập tin bootstrap.css thực tế để tập tin css của tôi, tuy nhiên nó không chính xác giống nhau cả thôi.

CHỈNH SỬA: SOLVED = Để sử dụng nhiều nguồn bạn phải đặt chúng vào một mảng.

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

+1

Tôi nghĩ rằng điều này xảy ra bởi vì bạn có hai f ile trong gulp.src của bạn. Hãy thử dòng này để xác minh (thay thế dòng gulp.src của bạn): 'return gulp.src ('www/bower_components/bootstrap/dist/css/bootstrap.css')' –

+0

@topleft đã thực hiện điều này! Khi sử dụng nhiều tệp nguồn có vẻ như bạn phải đặt nó bên trong một mảng hoặc sử dụng hợp nhất luồng. - https://github.com/gulpjs/gulp/blob/master/docs/recipes/using-multiple-sources-in-one-task.md –

+0

đặt chúng vào mảng giải quyết được sự cố. gulp.src ([,]) – Deke

Trả lời

50

Giống như @topleft đề cập, đó là lỗi trong cú pháp sử dụng nhiều tệp trong gulp.src của tôi. Để sử dụng nhiều nguồn bạn cần đặt chúng trong một mảng.

Ví dụ:

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

cách khác bạn cũng có thể thử với

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

nó nên thêm mỗi .css trong danh bạ của bạn nếu thats tác truy nã

+0

thứ tự quan trọng trong trường hợp này! Sau đó, bạn không thể làm điều đó. – dsandrade

0

Tôi có vấn đề này khi tôi đã cố gắng để đầu ra 2 file css và tôi không sử dụng mảng [].

Thay vì:

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

Sử dụng này:

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

Giải thích:

gulp.src(['./file1.scss', './file2.scss']); 
Các vấn đề liên quan