【发布时间】:2018-04-29 14:13:37
【问题描述】:
我已经阅读了我能找到的关于这个主题的所有教程、stackoverflow 问题、论坛,但仍然找不到适合我的解决方案。我确定这是我忽略的简单事情,这就是我寻求帮助的原因。这是我的文件夹结构供参考。
- 分布
- CSS
- img
- js
- index.html
- 源
- 萨斯
- img
- js
- index.html
- gulpfile.js
- package.json
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,如果有帮助的话。这真的让我发疯,所以我希望有人可以并且会提供帮助。谢谢! :)
【问题讨论】:
-
你在多个浏览器中试过了吗?
-
@TheodorB,是的,我尝试过使用 chrome canary、chrome 和 safari,结果相同。谢谢。
-
尝试从开发工具中检查网络选项卡,是否有任何错误?
-
@TheodorB,没有错误。
标签: javascript gulp