在centos下配置gulp启动遇到问题,求解救


bash报错如下:


 [18:05:55] Using gulpfile /www/webroot/gulpfile.js
[18:05:55] Starting 'default'...
gulp.run() has been deprecated. Use task dependencies or gulp.watch task triggering instead.
[18:05:55] Starting 'lint'...
[18:05:55] Finished 'lint' after 10 ms
[18:05:55] Starting 'sass'...
[18:05:55] 'sass' errored after 1.88 ms
[18:05:55] TypeError: Arguments to path.join must be strings
    at path.js:360:15
    at Array.filter (native)
    at Object.exports.join (path.js:358:36)
    at module.exports (/www/webroot/node_modules/gulp-ruby-sass/index.js:66:15)
    at Gulp.<anonymous> (/www/webroot/gulpfile.js:19:19)
    at module.exports (/www/webroot/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/www/webroot/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/www/webroot/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at /www/webroot/node_modules/gulp/node_modules/orchestrator/index.js:279:18
    at finish (/www/webroot/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:21:8)
[18:05:55] Finished 'default' after 23 ms

gulpfile.js的文件内容如下:


 var gulp = require('gulp');
//加载gulp-load-plugins插件,并马上运行它
//var plugins = require('gulp-load-plugins')();
//引入组件
var jshint = require('gulp-jshint');
var sass = require('gulp-ruby-sass');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
//检查脚本
gulp.task('lint', function() {
    gulp.src('./js/*.js')
        .pipe(jshint())
        .pipe(jshint.reporter('default'));
});

//编译Sass
gulp.task('sass', function() {
    gulp.src('./**/scss/*.scss', {base : './site'})
            .pipe(sass())
            .pipe(gulp.dest('./site/css'));

});
//合并,压缩文件
gulp.task('scripts', function() {
    gulp.src('./js/*.js')
        .pipe(concat('all.js'))
        .pipe(gulp.dest('./dist'))
        .pipe(rename('all.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('./dist'));
});
//默认任务


gulp.task('default', function(){
    gulp.run('lint', 'sass', 'scripts');

    // 监听文件变化
    gulp.watch('./js/*.js', function(){
        gulp.run('lint', 'sass', 'scripts');
    });
});

还有个问题,看别的教程说使用npm install --save-dev gulp会在当前路径有package.json。为什么我没有呢?

gulp sass centos7

炉心融红颜 9 years, 10 months ago

如果使用的 gulp-ruby-sass 版本是 1.0.0 以后的,对应 task 写法已经改变. 官方例子:


 var gulp = require('gulp');
var sass = require('gulp-ruby-sass');

gulp.task('sass', function() {
    return sass('source/') 
    .on('error', function (err) {
      console.error('Error!', err.message);
   })
    .pipe(gulp.dest('result'));
});

Azusa酱 answered 9 years, 10 months ago

Your Answer