Gulp手表不起作用 - 找不到模块livereload

时间:2015-11-25 09:20:57

标签: gulp

我正在试图称之为“gulp watch”命令,但它不起作用,它说:

module.js:340
    throw err;
    ^

Error: Cannot find module 'gulp-livereload'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:289:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous>    (/Applications/XAMPP/xamppfiles/htdocs/last/gulpfile.js:2:18)
    at Module._compile (module.js:425:26)
    at Object.Module._extensions..js (module.js:432:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)

我想这是我的gulpfile.js中的一个错误,但我不知道可能是什么。有人知道“livereload”发生了什么?我正在寻找互联网的答案,但我找不到任何东西,我试图(再次)安装npm,但它不起作用。

var gulp = require('gulp');
var livereload = require('gulp-livereload')
var uglify = require('gulp-uglifyjs');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');


 gulp.task('imagemin', function () {
    return gulp.src('./themes/theme_name/images/*')
        .pipe(imagemin({
            progressive: true,
            svgoPlugins: [{removeViewBox: false}],
            use: [pngquant()]
        }))
        .pipe(gulp.dest('./themes/theme_name/images'));
 });


  gulp.task('sass', function () {
  gulp.src('./themes/theme_name/sass/**/*.scss')
     .pipe(sourcemaps.init())
     .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
    .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 7', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
  .pipe(sourcemaps.write('./'))
  .pipe(gulp.dest('./themes/theme_name/styles'));
 });


 gulp.task('uglify', function() {
 gulp.src('./themes/theme_name/lib/*.js')
  .pipe(uglify('main.js'))
  .pipe(gulp.dest('./themes/theme_name/scripts'))
 });

 gulp.task('watch', function(){
    livereload.listen();

    gulp.watch('./themes/theme_name/sass/**/*.scss', ['sass']);
    gulp.watch('./themes/theme_name/lib/*.js', ['uglify']);
    gulp.watch(['./themes/theme_name/styles/style.css',   './themes/theme_name/**/*.twig', './themes/theme_name/scripts/*.js'], function (files){
    livereload.changed(files)
  });
});

1 个答案:

答案 0 :(得分:7)

在工作目录中试用此npm install -S gulp-livereload。可能你的package.json不包含这种依赖...