1 Star 0 Fork 246

zhangweijrdhcc/platform-plus-ui

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
gulpfile.js 2.53 KB
一键复制 编辑 原始数据 按行查看 历史
微同软件 提交于 2019-03-11 09:45 . Initial commit
const gulp = require('gulp')
const $ = require('gulp-load-plugins')();
const path = require('path');
const del = require('del');
const distPath = path.resolve('./dist');
let version = ''; // 版本号
let versionPath = ''; // 版本号路径
let env = ''; // 运行环境
// 创建版本号(年月日时分)
(function () {
const d = new Date();
const yy = d.getFullYear().toString().slice(2);
const MM = d.getMonth() + 1 >= 10 ? (d.getMonth() + 1) : '0' + (d.getMonth() + 1);
const DD = d.getDate() >= 10 ? d.getDate() : '0' + d.getDate();
const h = d.getHours() >= 10 ? d.getHours() : '0' + d.getHours();
const mm = d.getMinutes() >= 10 ? d.getMinutes() : '0' + d.getMinutes();
version = yy + MM + DD + h + mm;
versionPath = distPath + '/' + version;
})();
// 编译
gulp.task('build', $.shell.task(['node build/build.js']));
// 创建版本号目录
gulp.task('create:versionCatalog', ['build'], function () {
return gulp.src(`${distPath}/static/**/*`)
.pipe(gulp.dest(`${versionPath}/static/`))
});
// 替换${versionPath}/static/js/manifest.js window.SITE_CONFIG.cdnUrl占位变量
gulp.task('replace:cdnUrl', ['create:versionCatalog'], function () {
return gulp.src(`${versionPath}/static/js/manifest.js`)
.pipe($.replace(new RegExp(`"${require('./config').build.assetsPublicPath}"`, 'g'), 'window.SITE_CONFIG.cdnUrl + "/"'))
.pipe(gulp.dest(`${versionPath}/static/js/`))
});
// 替换${versionPath}/static/config/index-${env}.js window.SITE_CONFIG['version']配置变量
gulp.task('replace:version', ['create:versionCatalog'], function () {
return gulp.src(`${versionPath}/static/config/index-${env}.js`)
.pipe($.replace(/window.SITE_CONFIG\['version'\] = '.*'/g, `window.SITE_CONFIG['version'] = '${version}'`))
.pipe(gulp.dest(`${versionPath}/static/config/`))
});
// 合并${versionPath}/static/config/[index-${env}, init].js 至 ${distPath}/config/index.js
gulp.task('concat:config', ['replace:version'], function () {
return gulp.src([`${versionPath}/static/config/index-${env}.js`, `${versionPath}/static/config/init.js`])
.pipe($.concat('index.js'))
.pipe(gulp.dest(`${distPath}/config/`))
});
// 清空
gulp.task('clean', function () {
return del([distPath])
});
gulp.task('default', ['clean'], function () {
// 获取环境配置
env = 'prod'
// 开始打包编译
gulp.start(['build', 'create:versionCatalog', 'replace:cdnUrl', 'replace:version', 'concat:config'], function () {
// 清除, 编译 / 处理项目中产生的文件
del([`${distPath}/static`, `${versionPath}/static/config`])
})
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/zhangweijrdhcc/platform-plus-ui.git
git@gitee.com:zhangweijrdhcc/platform-plus-ui.git
zhangweijrdhcc
platform-plus-ui
platform-plus-ui
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385