我正在尝试调用“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)
});
});
请您参考如下方法:
在您的工作目录中尝试这个 npm install -S gulp-livereload
。可能您的 package.json 不包含此依赖项...