UNPKG

@molejs/mole-tools

Version:

Configuration and scripts for Mole App.

31 lines (30 loc) 1.3 kB
var path = require('path'); var htmlmin = require('gulp-htmlmin'); var shelljs = require('shelljs'); const project_dir = path.resolve(__dirname, '../../../../../') const currentPWD = path.resolve(__dirname, '../../') module.exports = function (gulp){ // 监听html变化 gulp.task('html', function(done){ // console.log(currentPWD) gulp.watch([project_dir + '/src/modules/**/*.html'], function(e){ // console.log(e.path) shelljs.exec('node '+ currentPWD +'/scripts/build-html.js --file ' + e.path); }); done(); }); gulp.task('build-html', function(){ return gulp.src([project_dir + '/modules/**/*.html']) .pipe(htmlmin({ removeComments: true,// 清除HTML注释 collapseWhitespace: true,// 压缩HTML collapseBooleanAttributes: true,//省略布尔属性的值 <input checked="true"/> ==> <input /> removeEmptyAttributes: true,//删除所有空格作属性值 <input id="" /> ==> <input /> removeScriptTypeAttributes: true,//删除<script>的type="text/javascript" removeStyleLinkTypeAttributes: true,//删除<style>和<link>的type="text/css" minifyJS: true, // 压缩页面JS minifyCSS: true // 压缩页面CSS })) .pipe(gulp.dest('../../modules')); }); }