0

不能使这个脚本工作,还需要建议:

当我在初始加载后更改任何文件时如何使浏览器重新加载?

有什么办法,当浏览器重新加载以保持在同一页面上(比如页面http://wpsass.dev/sass/mixin)而不重新加载基本网址(http://wpsass.dev

我正在尝试将其用于 wordpress 主题开发。

var gulp = require('gulp');
var sass = require('gulp-sass');
var browserSync = require('browser-sync').create();
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var gulpIf = require('gulp-if');
var autoprefixer = require('gulp-autoprefixer');

var theme = 'theme';

gulp.task('sass', function() {
  return gulp.src('code/wp-content/themes/'+theme+'/app/scss/**/*.scss') // Gets all files ending with .scss in app/scss
    .pipe(sass({
    	includePaths: [
    		'node_modules/susy/sass',
    		'node_modules/node-normalize-scss'
    	],
      outputStyle: 'expanded', // for production outputStyle: 'compressed'
      debugInfo: true,
    }))
    .pipe(autoprefixer({
      browsers: ['last 5 versions'],
      cascade: false
    }))
    .pipe(gulp.dest('code/wp-content/themes/'+theme+'/dist/css/'))
    .pipe( browserSync.stream() )
});

gulp.task('scripts', function() {
  return gulp.src([
      'code/wp-includes/js/jquery/jquery.js',
      'code/wp-includes/js/jquery/jquery-migrate.js',
      'code/wp-includes/js/wp-embed.js',
      'code/wp-content/themes/'+theme+'/app/js/script.js'
    ])
    .pipe(concat('all.js')) // concat all files in one file all.js
    .pipe(gulpIf('*.js', uglify())) // minify file if is .js format
    .pipe(gulp.dest('code/wp-content/themes/'+theme+'/dist/js/'))
    .pipe( browserSync.stream() )
});

gulp.task('watch', ['sass', 'scripts'], function (){
  browserSync.init({
    injectChanges: true,
    proxy: {
    target: "wpsass.dev",
      ws: true
    }
  });

  gulp.watch('code/wp-content/themes/'+theme+'/app/scss/**/*.scss', ['sass'] );
  gulp.watch('code/wp-content/themes/'+theme+'/app/js/**/*.js', ['scripts']);
  gulp.watch('code/wp-content/themes/'+theme+'/**/*.php', browserSync.reload);
});

终端结果:

PS D:\Projects\wp-sass> gulp watch
[15:25:45] Using gulpfile D:\Projects\wp-sass\gulpfile.js
[15:25:45] Starting 'sass'...
[15:25:45] Starting 'scripts'...
[15:25:48] Finished 'sass' after 3.08 s
[15:25:48] Finished 'scripts' after 3.08 s
[15:25:48] Starting 'watch'...
[15:25:48] Finished 'watch' after 276 ms
[BS] Proxying: http://wpsass.dev
[BS] Access URLs:
 -----------------------------------
       Local: http://localhost:3000
    External: http://10.2.101.8:3000
 -----------------------------------
          UI: http://localhost:3002
 UI External: http://10.2.101.8:3002
 -----------------------------------
[BS] Reloading Browsers...

4

0 回答 0