任务“浏览器同步”不在你的大文件中
我刚开始使用浏览器同步。 所以我开始学习一口饮料。 我使用npm install gulp -g
命令npm install gulp -g
。 在此之后,我使用下面的命令npm init
初始化了我的项目目录,其中包含package.json
文件。 然后,我通过npm install gulp --save-dev
命令在我的项目目录中安装了gulp。我还通过npm install browser-sync --save-dev
命令npm install browser-sync --save-dev
。
现在我试图运行浏览gulp browser-sync
使用gulp gulp browser-sync
命令,这给我一个错误任务“浏览器同步”不在你gulp文件
以下是我的gulpfiles.js文件
var gulp = require('gulp'); var browserSync = require('browser-sync').create(); // process JS files and return the stream. gulp.task('js', function () { return gulp.src('js/*js') .pipe(browserify()) .pipe(uglify()) .pipe(gulp.dest('dist/js')); }); // create a task that ensures the `js` task is complete before // reloading browsers gulp.task('js-watch', ['js'], function (done) { browserSync.reload(); done(); }); // use default task to launch Browsersync and watch JS files gulp.task('serve', ['js'], function () { // Serve files from the root of this project browserSync.init({ server: { baseDir: "./" } }); // add browserSync.reload to the tasks array to make // all browsers reload after tasks are complete. gulp.watch("js/*.js", ['js-watch']); });
我已经试过包括module.exports = gulp;
在开始以及在gulpfile.js的结尾行,但错误仍然存在。 我目前的gulp版本是mac OSX 10.12.3上的3.9.1
请帮我卡住了。
问题是你叫你的任务服务器而不是browserSync
:
// use default task to launch Browsersync and watch JS files // NOTE how this task is called serve: gulp.task('serve', ['js'], function () { // Serve files from the root of this project browserSync.init({ server: { baseDir: "./" } });
你可以改变它的名字:
// use default task to launch Browsersync and watch JS files // NOTE at the name of the task now gulp.task('browser-sync', ['js'], function () { // Serve files from the root of this project browserSync.init({ server: { baseDir: "./" } });
- 为什么后续的HTTP请求
- BrowserSync非常慢
- 使用gulp时,Css样式表有错误的path
- browserSync的modRewrite不适用于angularjs html5mode的path“app / index.html”与吞咽
- BrowserSync不断地使用Express / Gulp进行GET
- Laravel-mix – BrowserSync在event.js上抛出错误:160
- Gulp在我的macOS上没有成功运行
- Gulp突然停止了与BrowserSync的合作。 node_modules / glob-watcher上的RangeError
- Gulp.js浏览器同步不会重新加载我的浏览器