我已经阅读了每个教程,stackoverflow问题,我可以在这个主题上找到的讨论论坛,但仍然无法找到适合我的解决方案。我确信这是一个简单的我忽略了这就是为什么我要求帮助。这是我的文件夹结构供参考。
browserSync将正确初始化并在浏览器中显示该页面。当我对html,css或js文件进行更改时,终端会告诉我它正在重新加载浏览器,但浏览器永远不会重新加载。如果我手动刷新浏览器,那么更改会正确显示但是browserSync应该自动刷新吗?
我是否需要制作某种返回流或.pipe(browserSync.stream());在我的复制任务结束时?
var gulp = require("gulp"),
browserSync = require("browser-sync").create(),
sass = require("gulp-sass"),
autoprefixer = require("gulp-autoprefixer"),
jasmine = require("gulp-jasmine-phantom"),
concat = require("gulp-concat"),
uglify = require("gulp-uglify"),
babel = require("gulp-babel"),
sourcemaps = require("gulp-sourcemaps"),
imagemin = require("gulp-imagemin");
gulp.task("default", ["styles", "copy-html", "copy-img", "scripts", "browser-sync", "watch"], function(){
});
gulp.task("watch", ["browser-sync"], function() {
gulp.watch("src/img/*", ["copy-img", browserSync.reload]);
gulp.watch("src/index.html", ["copy-html", browserSync.reload]);
gulp.watch("src/sass/**/*.scss", ["styles", browserSync.reload]);
gulp.watch("src/js/**/*.js", ["scripts", browserSync.reload]);
});
gulp.task("browser-sync", function(){
browserSync.init({
server: {
baseDir: "dist/"
}
});
});
gulp.task("styles", function () {
return gulp.src("src/sass/**/*.scss")
.pipe(sass({outputStyle: "compressed"}).on("error", sass.logError))
.pipe(autoprefixer({
browsers: ["last 2 versions"],
cascade: false
}))
.pipe(gulp.dest("dist/css"));
});
gulp.task("copy-html", function() {
return gulp.src("src/index.html")
.pipe(gulp.dest("./dist"));
});
gulp.task("scripts", function() {
return gulp.src("src/js/**/*.js")
.pipe(babel())
.pipe(sourcemaps.init())
.pipe(concat("all.js"))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest("dist/js"));
});
gulp.task("copy-img", function() {
return gulp.src("src/img/*")
.pipe(imagemin())
.pipe(gulp.dest("dist/img"));
});
gulp.task("tests", function() {
gulp.src("tests/spec/extraSpec.js")
.pipe(jasmine({
integration: true,
vendor: "src/js/**/*.js"
}));
});
我也想知道我在package.json文件中的依赖项是否正确。
{
"title": "Matthew J. Whitney - Portfolio Site",
"name": "portfolio-site",
"description": "A smooth scrolling navigation built with Bootstrap",
"keywords": [
"css",
"sass",
"html",
"responsive",
"javascript"
],
"homepage": "https://www.matthewjwhitney.com",
"author": "Matthew J. Whitney",
"repository": {
"type": "git",
"url": "https://github.com/matthewjwhitney/portfolio-site.git"
},
"dependencies": {
"ajv": "^6.4.0",
"babel-core": "^6.26.3",
"bootstrap": "^4.0.0",
"gulp-clean-css": "^3.9.3",
"gulp-cssnano": "^2.1.3",
"gulp-htmlclean": "^2.7.22",
"gulp-inject": "^4.3.2",
"gulp-rename": "^1.2.2",
"gulp-webserver": "^0.9.1",
"jquery": "3.3.1",
"jquery.easing": "^1.4.1",
"phantomjs": "^2.1.7",
"popper": "^1.0.1",
"popper.js": "^1.14.3"
},
"devDependencies": {
"browser-sync": "^2.23.6",
"del": "^3.0.0",
"eslint": "^4.19.1",
"eslint-plugin-react": "^7.7.0",
"gulp": "^3.9.1",
"gulp-autoprefixer": "^5.0.0",
"gulp-babel": "^7.0.1",
"gulp-cache": "^1.0.2",
"gulp-concat": "^2.6.1",
"gulp-eslint": "^4.0.2",
"gulp-imagemin": "^4.1.0",
"gulp-jasmine-phantom": "^3.0.0",
"gulp-sass": "^4.0.1",
"gulp-sourcemaps": "^2.6.4",
"gulp-uglify": "^3.0.0",
"gulp-useref": "^3.1.5",
"run-sequence": "^2.2.1"
}
}
如果有帮助的话,这里是a link to my GitHub repo。这真的让我发疯,所以我希望那里的人可以并且会有所帮助。谢谢! :)