代码拉取完成,页面将自动刷新
'use strict'
const gulp = require('gulp')
const less = require('gulp-less')
const jade = require('gulp-jade')
const watch = require('gulp-watch')
const plumber = require('gulp-plumber')
const autoprefixer = require('autoprefixer')
const postcss = require('gulp-postcss')
const sourcemaps = require('gulp-sourcemaps')
const bs = require('browser-sync').create()
// 配置路径
const direction = {
jade: {
src: ['./views/**/*.jade', '!./views/common/**/*.jade'],
dest: './views',
},
less: {
src: ['./public/**/*.less'],
dest: './public',
},
}
gulp.task('jade', () => {
return watch(direction.jade.src, { ignoreInitial: false })
.pipe(sourcemaps.init())
.pipe(plumber())
.pipe(jade({ pretty: true })).on('error', (error) => { console.log(error.message) })
.pipe(sourcemaps.write('./sourcemaps'))
.pipe(gulp.dest(direction.jade.dest))
})
gulp.task('less', () => {
return watch(direction.less.src, { ignoreInitial: false })
.pipe(sourcemaps.init())
.pipe(plumber())
.pipe(less({ compress: false })).on('error', (error) => { console.log(error.message) })
.pipe(postcss([autoprefixer({
browsers: [
'Android >= 4',
'Chrome >= 35',
'Firefox >= 31',
'Explorer >= 9',
'iOS >= 7',
'Opera >= 12',
'Safari >= 7.1',
'IE >= 8',
]
})]))
.pipe(sourcemaps.write('./sourcemaps'))
.pipe(gulp.dest(direction.less.dest))
})
gulp.task('bs-server', () => {
bs.init({
server: {
baseDir: direction.jade.dest,
directory: true
},
port: 3001,
files: [direction.less.dest + '/**/*.css'],
})
})
gulp.task('bs-proxy', () => {
bs.init({
proxy: 'localhost',
port: 3001,
files: [direction.less.dest + '/**/*.css'],
})
})
gulp.task('default', ['jade', 'less', 'bs-server'])
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。