我已經建立了我的WordPress站點的本地副本,並吸引了Gulp來編譯.less,JS等。 PHP的瀏覽器更新,但是當我保存.less文件時,.css被編譯,但瀏覽器不更新。Gulp中的BrowserSync正在重新加載瀏覽器,但直播css不更新瀏覽器
當我在不同的網站上使用這個相同的gulp文件時,它完全可以正常工作。
誰能告訴我什麼可能阻止BrowserSync更新CSS更改(但HTML/PHP更改更新正常),並會影響某些網站,但不是其他人? (我使用OSX Yosemite & Chrome瀏覽器FYI)。
這裏是我的gulpfile:
/* config */
var PROXY_ADDR = 'playitinteractive.dev',
\t ASSET_PATH = 'html/wp-content/themes/playitinteractive/assets';
\t
var globs = {
\t js: [
\t \t ASSET_PATH + '/js/src/**/*.js',
\t ],
\t less: [
\t \t ASSET_PATH + 'css/less/**/*.less',
\t ],
\t files: [
\t \t '**/.htaccess',
\t \t '**/*.+(html|php|jpg|jpeg|gif|png)',
\t ],
};
var dests = {
\t js: ASSET_PATH + '/js',
\t less: ASSET_PATH + '/css',
}
/* includes */
var gulp = require('gulp'),
\t gutil = require('gulp-util'),
\t rename = require('gulp-rename'),
\t
\t // watching
\t browserSync = require('browser-sync'),
\t \t
\t // js
\t concat = require('gulp-concat'),
\t uglify = require('gulp-uglify'),
\t ngAnnotate = require('gulp-ng-annotate'),
\t
\t // css
\t less = require('gulp-less'),
\t autoprefixer = require('gulp-autoprefixer'),
\t minifyCss = require('gulp-minify-css');
/* tasks */
gulp
\t // build
\t .task('js', function(){
\t \t return gulp.src(globs.js)
\t \t \t .pipe(concat('base.js'))
\t \t \t .pipe(ngAnnotate())
\t \t \t .pipe(gulp.dest(dests.js))
\t \t \t
\t \t \t .pipe(rename({suffix: '.min'}))
\t \t \t .pipe(uglify())
\t \t \t .pipe(gulp.dest(dests.js))
\t \t \t
\t \t \t .pipe(browserSync.reload({stream:true}));
\t })
\t .task('less', function(){
\t \t return gulp.src(globs.less.concat(['!' + ASSET_PATH + '/less/**/*.inc.less']))
\t \t \t .pipe(less())
\t \t \t .pipe(autoprefixer('last 2 versions'))
\t \t \t .pipe(minifyCss())
\t \t \t .pipe(gulp.dest(dests.less))
\t \t \t
\t \t \t .pipe(browserSync.reload({stream:true}));
\t })
\t .task('build', ['js','less'])
\t
\t
\t // watch
\t .task('js.watch', ['js'], function(){
\t \t gulp.watch(globs.js, ['js']);
\t })
\t .task('less.watch', ['less'], function(){
\t \t gulp.watch(globs.less, ['less']);
\t })
\t .task('watch', ['js.watch','less.watch'], function(){
\t \t browserSync.init({
\t \t \t files: globs.files,
\t \t \t proxy: PROXY_ADDR,
\t \t \t watchOptions: {debounce: 400},
\t \t \t ghostMode: false,
\t \t \t notify: false,
\t \t \t open: !! gutil.env.open, // call `gulp --open` to start gulp and also open a new browser window
\t \t });
\t })
\t
\t // default
\t .task('default', ['watch'])
\t
{
"devDependencies": {
"browser-sync": "^1.3.0",
"gulp": "^3.8.6",
"gulp-autoprefixer": "0.0.8",
"gulp-concat": "^2.3.4",
"gulp-less": "^1.3.3",
"gulp-minify-css": "^0.3.7",
"gulp-ng-annotate": "^0.2.0",
"gulp-rename": "^1.2.0",
"gulp-uglify": "^0.3.1",
"gulp-util": "^3.0.0"
}
}
你能檢查你使用的瀏覽器同步的實際版本是什麼?最新的是1.9.1。它的文檔沒有列出'browserSync.init'語法。 – Heikki 2015-01-21 14:32:23
http://www.browsersync.io/docs/gulp/ – Heikki 2015-01-21 14:33:41