如果我更新CSS或html模板,我已安装browserSync以使我的浏览器自动刷新。
在我的gulp文件中:
var browserSync = require('browser-sync').create();
由我的观察任务决定:
// Static Server + watching scss/html files
gulp.task('serve', ['app-css'], function() {
browserSync.init({
// server: "./app"
proxy: 'http://localhost/static/dashboard/app/'
});
gulp.watch("sass-smacss/sass/**/*.scss", ['app-css']);
gulp.watch("app/**/*.html").on('change', browserSync.reload);
});
我有一个本地服务器,因此我正在使用上面的proxy
链接。
无论如何我运行了gulp serve
并自动启动了一个新的Chrome窗口,其中包含以下路径:http://localhost:3000/static/dashboard/app/#/login
接下来,我只是在我的一个sass文件中点击保存,它引发了以下错误:
[21:52:37] Starting 'app-css'... /Users/leongaban/Projects/TickerTags/dashboard/node_modules/browser-sync/lib/file-utils.js:48 if (!_.contains(options.get("injectFileTypes").toJS(), obj.ext)) { ^
TypeError: _.contains is not a function
at Object.fileUtils.getFileInfo (/Users/leongaban/Projects/TickerTags/dashboard/node_modules/browser-sync/lib/file-utils.js:48:16)
at Object.fileUtils.changedFile (/Users/leongaban/Projects/TickerTags/dashboard/node_modules/browser-sync/lib/file-utils.js:26:57)
at EventEmitter.events.file:changed (/Users/leongaban/Projects/TickerTags/dashboard/node_modules/browser-sync/lib/internal-events.js:13:23)
at emitOne (events.js:77:13)
at EventEmitter.emit (events.js:169:7)
at Object.emitChangeEvent (/Users/leongaban/Projects/TickerTags/dashboard/node_modules/browser-sync/lib/public/public-utils.js:13:17)
at Transform.reload._transform (/Users/leongaban/Projects/TickerTags/dashboard/node_modules/browser-sync/lib/public/stream.js:70:31)
at Transform._read (_stream_transform.js:167:10)
at Transform._write (_stream_transform.js:155:12)
at doWrite (_stream_writable.js:292:12)
以下是/node_modules/browser-sync/lib/file-utils.js:48
/**
* @param data
* @param options
* @returns {{assetFileName: *, fileExtension: String}}
*/
getFileInfo: function (data, options) {
data.ext = require("path").extname(data.path).slice(1);
data.basename = require("path").basename(data.path);
var obj = {
ext: data.ext,
path: data.path,
basename: data.basename,
type: "inject"
};
// RELOAD page
if (!_.contains(options.get("injectFileTypes").toJS(), obj.ext)) {
obj.url = obj.path;
obj.type = "reload";
}
obj.path = data.path;
obj.log = data.log;
return obj;
}
答案 0 :(得分:0)
Per @Phil https://github.com/BrowserSync/browser-sync/issues/976
不得不升级lodash,现在它可以正常工作。