代码拉取完成,页面将自动刷新
const gulp = require('gulp')
const minifycss = require('gulp-clean-css')
const uglify = require('gulp-uglify')
const htmlmin = require('gulp-htmlmin')
const cssnano = require('gulp-cssnano')
const htmlclean = require('gulp-htmlclean')
const del = require('del')
const babel = require('gulp-babel')
const autoprefixer = require('gulp-autoprefixer')
const connect = require('gulp-connect')
const pug = require('gulp-pug')
const sass = require('gulp-sass')
sass.compiler = require('node-sass')
const config = require('./config.json')
gulp.task('clean', function () {
return del(['./dist/css/', './dist/js/'])
})
gulp.task('css', function () {
return gulp
.src('./src/css/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(minifycss({ compatibility: 'ie8' }))
.pipe(autoprefixer({ browsers: ['last 2 version'] }))
.pipe(cssnano({ reduceIdents: false }))
.pipe(gulp.dest('./dist/css'))
})
gulp.task('html', function () {
return gulp
.src('./dist/index.html')
.pipe(htmlclean())
.pipe(htmlmin())
.pipe(gulp.dest('./dist'))
})
gulp.task('js', function () {
return gulp
.src('./src/js/*.js')
.pipe(babel({ presets: ['@babel/preset-env'] }))
.pipe(uglify())
.pipe(gulp.dest('./dist/js'))
})
gulp.task('pug', function () {
return gulp
.src('./src/index.pug')
.pipe(pug({ data: config }))
.pipe(gulp.dest('./dist'))
})
gulp.task('assets', function () {
return gulp
.src(['./src/assets/**/*'])
.pipe(gulp.dest('./dist/assets'));
})
gulp.task('build', gulp.series('clean', 'assets', 'pug', 'css', 'js', 'html'))
gulp.task('default', gulp.series('build'))
gulp.task('watch', function () {
gulp.watch('./src/components/*.pug', gulp.parallel('pug'))
gulp.watch('./src/index.pug', gulp.parallel('pug'))
gulp.watch('./src/css/**/*.scss', gulp.parallel(['css']))
gulp.watch('./src/js/*.js', gulp.parallel(['js']))
connect.server({
root: 'dist',
livereload: true,
port: 8080
})
})
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。