代码拉取完成,页面将自动刷新
const {series, watch, src, dest, parallel} = require('gulp');
const pump = require('pump');
// gulp plugins and utils
const livereload = require('gulp-livereload');
const postcss = require('gulp-postcss');
const zip = require('gulp-zip');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const beeper = require('beeper');
// postcss plugins
const autoprefixer = require('autoprefixer');
const colorFunction = require('postcss-color-mod-function');
const cssnano = require('cssnano');
const easyimport = require('postcss-easy-import');
function serve(done) {
livereload.listen();
done();
}
const handleError = (done) => {
return function (err) {
if (err) {
beeper();
}
return done(err);
};
};
function html(done) {
pump([
src(['templates/*.html', 'templates/partials/**/*.html']),
livereload()
], handleError(done));
}
function css(done) {
pump([
src('templates/assets/css/*.css', {sourcemaps: true}),
postcss([
easyimport,
colorFunction(),
autoprefixer(),
cssnano()
]),
dest('templates/assets/built/', {sourcemaps: '.'}),
livereload()
], handleError(done));
}
function js(done) {
pump([
src([
// pull in lib files first so our own code can depend on it
'templates/assets/js/lib/*.js',
'templates/assets/js/*.js'
], {sourcemaps: true}),
concat('casper.js'),
uglify(),
dest('templates/assets/built/', {sourcemaps: '.'}),
livereload()
], handleError(done));
}
function zipper(done) {
const filename = require('./package.json').name + '-' + require('./package.json').version + '.zip';
pump([
src([
'**',
'!node_modules', '!node_modules/**',
'!dist', '!dist/**',
'!yarn-error.log',
'!yarn.lock',
'!gulpfile.js'
]),
zip(filename),
dest('dist/')
], handleError(done));
}
const cssWatcher = () => watch('templates/assets/css/**', css);
const jsWatcher = () => watch('templates/assets/js/**', js);
const htmlWatcher = () => watch(['templates/*.html', 'templates/partials/**/*.html'], html);
const watcher = parallel(cssWatcher, jsWatcher, htmlWatcher);
const build = series(css, js);
exports.build = build;
exports.zip = series(build, zipper);
exports.default = series(build, serve, watcher);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。