Javascript 任务';浏览器同步';不在你的肚子里
我刚开始使用browsersync。所以我开始学习吞咽。 我使用Javascript 任务';浏览器同步';不在你的肚子里,javascript,node.js,macos,gulp,browser-sync,Javascript,Node.js,Macos,Gulp,Browser Sync,我刚开始使用browsersync。所以我开始学习吞咽。 我使用npm install gulp-g命令安装了gulp。在此之后,我通过以下命令npminit用package.json文件初始化了我的项目目录。然后,我通过npm install gulp--save dev命令在我的项目目录中安装了gulp。我还通过npm install browser sync--save dev命令安装了browsersync 现在,我尝试使用gulp bygulp browser sync命令运行brow
npm install gulp-g
命令安装了gulp。在此之后,我通过以下命令npminit
用package.json
文件初始化了我的项目目录。然后,我通过npm install gulp--save dev
命令在我的项目目录中安装了gulp。我还通过npm install browser sync--save dev
命令安装了browsersync
现在,我尝试使用gulp bygulp browser sync
命令运行browsersync,该命令给我一个错误任务“browser sync”不在您的gulpfile中
下面是我的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版本是MacOSX10.12.3上的3.9.1
请帮帮我,我卡住了 问题是您调用了任务服务
,而不是浏览器同步
:
// 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: "./"
}
});
问题是您将任务称为服务
,而不是浏览器同步
:
// 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: "./"
}
});
我有一个疑问。有多个任务具有不同的名称,但为什么选择此任务。顺便说一句,这个例子来自browsersync文档。我选择这个任务是因为它是初始化browsersync服务器的任务。您是否尝试过使用当前代码运行gulp serve
,并查看browserSync是否正常工作?没问题,happy coding:)我有疑问。有多个任务具有不同的名称,但为什么选择此任务。顺便说一句,这个例子来自browsersync文档。我选择这个任务是因为它是初始化browsersync服务器的任务。您是否尝试过使用当前代码运行gulp serve
,并查看browserSync是否正常工作?没问题,快乐编码:)