我在从 gulpfile.js 启动 watch() 任务时遇到了一点麻烦。
运行 gulp 命令后,我看到了以下内容:
[19:58:36] 'watch' errored after 1.23 s
[19:58:36] Error: EACCES: permission denied, stat '/usr/sbin/weakpass_edit'
[19:58:36] 'default' errored after 1.24 s
我已导航到生成错误的目录,并且weakpass_edit是一个别名,无法找到原始目录。
我尝试删除 node、npm 和所有 dev 依赖项。我也尝试查看我拥有的其他 Mac,它们都是一样的。
当前运行带有 MAMP Pro 的 Mac OS 10.15 Beta (19A546d)。
这确实超出了我的能力范围,所以我不太清楚这是什么或者该怎么办。
任何帮助将不胜感激。
Gulpfile.js如下:
var themename = 'gulp-sandbox';
var gulp = require( 'gulp' ),
autoprefixer = require( 'gulp-autoprefixer' ),
browserSync = require( 'browser-sync' ).create(),
reload = browserSync.reload,
sass = require( 'gulp-sass' ),
cleanCSS = require( 'gulp-clean-css' ),
sourcemaps = require( 'gulp-sourcemaps' ),
concat = require( 'gulp-concat' ),
imagemin = require( 'gulp-imagemin' ),
changed = require( 'gulp-changed' ),
uglify = require( 'gulp-uglify' ),
lineec = require( 'gulp-line-ending-corrector' );
var root = '/',
scss = root + 'sass/',
js = root + 'src/js/',
jsdist = root + 'dist/js/';
// Watch Files
var PHPWatchFiles = root + '**/*.php',
styleWatchFiles = root + '**/*.scss';
// Used to concat the files in a specific order.
var jsSRC = [
js + 'bootstrap.bundle.js',
js + 'bootstrap-hover.js',
js + 'nav-scroll.js',
js + 'prism.js',
js + 'resizeSensor.js',
js + 'sticky-sidebar.js',
js + 'sticky-sb.js',
js + 'skip-link-focus-fix.js'
];
// Used to concat the files in a specific order.
var cssSRC = [
root + 'src/css/bootstrap.css',
root + 'src/css/all.css',
root + 'src/css/prism.css',
root + 'style.css',
];
var imgSRC = root + 'src/images/*',
imgDEST = root + 'dist/images/';
function css() {
return gulp.src([scss + 'style.scss'])
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sass({
outputStyle: 'expanded'
}).on('error', sass.logError))
.pipe(autoprefixer('last 2 versions'))
.pipe(sourcemaps.write())
.pipe(lineec())
.pipe(gulp.dest(root));
}
function concatCSS() {
return gulp.src(cssSRC)
.pipe(sourcemaps.init({loadMaps: true, largeFile: true}))
.pipe(concat('style.min.css'))
.pipe(cleanCSS())
.pipe(sourcemaps.write('./maps/'))
.pipe(lineec())
.pipe(gulp.dest(scss));
}
function javascript() {
return gulp.src(jsSRC)
.pipe(concat('devwp.js'))
.pipe(uglify())
.pipe(lineec())
.pipe(gulp.dest(jsdist));
}
function imgmin() {
return gulp.src(imgSRC)
.pipe(changed(imgDEST))
.pipe( imagemin([
imagemin.gifsicle({interlaced: true}),
imagemin.jpegtran({progressive: true}),
imagemin.optipng({optimizationLevel: 5})
]))
.pipe( gulp.dest(imgDEST));
}
function watch() {
browserSync.init({
open: 'local',
proxy: 'gulp-sandbox',
// port: 8080,
});
gulp.watch(styleWatchFiles, gulp.series([css, concatCSS]));
gulp.watch(jsSRC, javascript);
gulp.watch(imgSRC, imgmin);
gulp.watch([PHPWatchFiles]).on('change', browserSync.reload);
}
exports.css = css;
exports.concatCSS = concatCSS;
exports.javascript = javascript;
exports.watch = watch;
exports.imgmin = imgmin;
var build = gulp.parallel(watch);
gulp.task('default', build);
答案1
我也遇到过同样的错误。就我而言,解决方案是路径冲突:
browserSync.init({
files: ['/**/*.php']
});
并通过改变来解决
browserSync.init({
files: ['**/*.php']
});