30 Star 153 Fork 44

KingWTD/mockcat

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gulpfile.js 3.80 KB
一键复制 编辑 原始数据 按行查看 历史
KingWTD 提交于 2021-01-16 20:07 +08:00 . 更新打包与模板
/**
* Build files
* @author Wangtd
*/
const path = require("path");
const gulp = require('gulp');
const gulpIf = require('gulp-if');
const gulpIgnore = require('gulp-ignore');
const clean = require('gulp-clean');
const cleanCss = require("gulp-clean-css");
const htmlmin = require("gulp-htmlmin");
const rjs = require('gulp-requirejs');
const ngAnnotate = require('gulp-ng-annotate');
const uglifyes = require('uglify-es');
const uglifyComposer = require('gulp-uglify/composer');
const uglify = uglifyComposer(uglifyes, console);
const gulpSequence = require('gulp-sequence');
// clean
gulp.task('cleanall', function () {
return gulp.src(['temp', 'dist'], {
read: false, allowEmpty: true
})
.pipe(clean({ force: true }));
});
gulp.task('clean', function () {
return gulp.src('temp', { read: false })
.pipe(clean({ force: true }));
});
// css
gulp.task('cssmin', function() {
return gulp.src('app/**/*.css')
.pipe(gulpIf(function(file) {
var filename = path.basename(file.path);
return !/[\.-]min\.css$/.test(filename);
}, cleanCss({
rebase: false,
compatibility: '*',
keepSpecialComments: '*'
})))
.pipe(gulp.dest('temp/dist'));
});
// html
gulp.task('htmlmin', function() {
return gulp.src('app/**/*.html')
.pipe(htmlmin({
collapseWhitespace: true,
conservativeCollapse: false,
collapseInlineTagWhitespace: false,
//preserveLineBreaks: true,
keepClosingSlash: true,
ignoreCustomFragments: [],
minifyCSS: {
compatibility: '*',
keepSpecialComments: '*'
},
minifyJS: true
}))
.pipe(gulp.dest('temp/dist'));
});
// js
gulp.task('jsmin', function() {
return gulp.src('app/**/*.js')
// angularjs
.pipe(gulpIf(function(file) {
return /(app|config)\.js$/.test(file.path) ||
/\/app\/views\/.+\.js$/.test(file.path.replace(/\\/g, '/'));
}, ngAnnotate()))
// js
.pipe(gulpIf(function(file) {
var filename = path.basename(file.path);
return !/[\.-](min|dist|pack)\.js$/.test(filename);
}, uglify()))
.pipe(gulp.dest('temp/dist'));
});
// others
gulp.task('others', function() {
return gulp.src('app/**/*.*')
.pipe(gulpIgnore.exclude(function(file) {
var filename = path.basename(file.path);
return /\.(css|html|js)$/.test(filename);
}))
.pipe(gulp.dest('temp/dist'));
});
// build require.js
gulp.task('buildall', function() {
return new Promise(function(resolve, reject) {
try {
resolve(rjs({
appDir: 'temp/dist',
baseUrl: './',
siteRoot: '../temp/',
//buildCSS: false,
mainConfigFile: 'temp/dist/main.js',
useStrict: false,
//findNestedDependencies: true,
removeCombined: true,
optimize: 'none',//'uglify2',
skipDirOptimize: true,
optimizeCss: 'none',//'standard.keepLines',
name: 'build',
//include: 'app',
//insertRequire: ['build'],
dir: 'temp/app'
}));
} catch(e) {
reject(e);
}
});
});
// copy all resources
gulp.task('copyall', function() {
return gulp.src('temp/app/**/*').pipe(gulp.dest('dist'));
});
gulp.task('default', gulpSequence(
'cleanall',
['cssmin', 'htmlmin', 'jsmin', 'others'],
'buildall',
'copyall',
'clean'
));
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
NodeJS
1
https://gitee.com/kingwtd/mockcat.git
git@gitee.com:kingwtd/mockcat.git
kingwtd
mockcat
mockcat
master

搜索帮助