更新gulp依赖,兼容nodejs12

master
LGH 6 years ago
parent 88c6cc30ee
commit c553a0cbba

@ -1,66 +1,64 @@
var gulp = require('gulp'); var gulp = require('gulp');
var $ = require('gulp-load-plugins')(); var $ = require('gulp-load-plugins')();
var path = require('path'); var path = require('path');
var del = require('del'); var del = require('del');
var exec = require('child_process').exec;
var distPath = path.resolve('./dist'); var distPath = path.resolve('./dist');
var version = ''; // 版本号 var version = ''; // 版本号
var versionPath = ''; // 版本号路径 var versionPath = ''; // 版本号路径
var env = ''; // 运行环境 var env = 'prod'; // 运行环境
// 创建版本号(年月日时分) // 创建版本号(年月日时分)
(function () { (function (cb) {
var d = new Date(); var d = new Date();
var yy = d.getFullYear().toString().slice(2); var yy = d.getFullYear().toString().slice(2);
var MM = d.getMonth() + 1 >= 10 ? (d.getMonth() + 1) : '0' + (d.getMonth() + 1); var MM = d.getMonth() + 1 >= 10 ? (d.getMonth() + 1) : '0' + (d.getMonth() + 1);
var DD = d.getDate() >= 10 ? d.getDate() : '0' + d.getDate(); var DD = d.getDate() >= 10 ? d.getDate() : '0' + d.getDate();
var h = d.getHours() >= 10 ? d.getHours() : '0' + d.getHours(); var h = d.getHours() >= 10 ? d.getHours() : '0' + d.getHours();
var mm = d.getMinutes() >= 10 ? d.getMinutes() : '0' + d.getMinutes(); var mm = d.getMinutes() >= 10 ? d.getMinutes() : '0' + d.getMinutes();
version = yy + MM + DD + h + mm; version = yy + MM + DD + h + mm;
versionPath = distPath + '/' + version; versionPath = distPath + '/' + version;
})(); })();
// 编译 // 编译
gulp.task('build', $.shell.task([ 'node build/build.js' ])); gulp.task('build', function (cb) {
exec('node build/build.js', () => cb())
});
// 创建版本号目录 // 创建版本号目录
gulp.task('create:versionCatalog', ['build'], function () { gulp.task('create:versionCatalog', function (cb) {
return gulp.src(`${distPath}/static/**/*`) gulp.src(`${distPath}/static/**/*`)
.pipe(gulp.dest(`${versionPath}/static/`)) .pipe(gulp.dest(`${versionPath}/static/`)).on('end', () => cb())
}); });
// 替换${versionPath}/static/js/manifest.js window.SITE_CONFIG.cdnUrl占位变量 // 替换${versionPath}/static/js/manifest.js window.SITE_CONFIG.cdnUrl占位变量
gulp.task('replace:cdnUrl', ['create:versionCatalog'], function () { gulp.task('replace:cdnUrl', function (cb) {
return gulp.src(`${versionPath}/static/js/manifest.js`) gulp.src(`${versionPath}/static/js/manifest.js`)
.pipe($.replace(new RegExp(`"${require('./config').build.assetsPublicPath}"`, 'g'), 'window.SITE_CONFIG.cdnUrl + "/"')) .pipe($.replace(new RegExp(`"${require('./config').build.assetsPublicPath}"`, 'g'), 'window.SITE_CONFIG.cdnUrl + "/"'))
.pipe(gulp.dest(`${versionPath}/static/js/`)) .pipe(gulp.dest(`${versionPath}/static/js/`)).on('end', () => cb())
}); });
// 替换${versionPath}/static/config/index-${env}.js window.SITE_CONFIG['version']配置变量 // 替换${versionPath}/static/config/index-${env}.js window.SITE_CONFIG['version']配置变量
gulp.task('replace:version', ['create:versionCatalog'], function () { gulp.task('replace:version', function (cb) {
return gulp.src(`${versionPath}/static/config/index-${env}.js`) gulp.src(`${versionPath}/static/config/index-${env}.js`)
.pipe($.replace(/window.SITE_CONFIG\['version'\] = '.*'/g, `window.SITE_CONFIG['version'] = '${version}'`)) .pipe($.replace(/window.SITE_CONFIG\['version'\] = '.*'/g, `window.SITE_CONFIG['version'] = '${version}'`))
.pipe(gulp.dest(`${versionPath}/static/config/`)) .pipe(gulp.dest(`${versionPath}/static/config/`)).on('end', () => cb())
}); });
// 合并${versionPath}/static/config/[index-${env}, init].js 至 ${distPath}/config/index.js // 合并${versionPath}/static/config/[index-${env}, init].js 至 ${distPath}/config/index.js
gulp.task('concat:config', ['replace:version'], function () { gulp.task('concat:config', function (cb) {
return gulp.src([`${versionPath}/static/config/index-${env}.js`, `${versionPath}/static/config/init.js`]) gulp.src([`${versionPath}/static/config/index-${env}.js`, `${versionPath}/static/config/init.js`])
.pipe($.concat('index.js')) .pipe($.concat('index.js'))
.pipe(gulp.dest(`${distPath}/config/`)) .pipe(gulp.dest(`${distPath}/config/`)).on('end', () => cb())
}); });
// 清空 // 清空
gulp.task('clean', function () { gulp.task('clean', function (cb) {
return del([versionPath]) del([versionPath])
}); });
gulp.task('default', ['clean'], function () { gulp.task('default', gulp.series('build', gulp.series('create:versionCatalog', 'replace:cdnUrl', 'replace:version', 'concat:config'), function (cb) {
// 获取环境配置 del([`${distPath}/static`, `${versionPath}/static/config`])
env = process.env.npm_config_qa ? 'qa' : process.env.npm_config_uat ? 'uat' : 'prod' cb()
// 开始打包编译 }));
gulp.start(['build', 'create:versionCatalog', 'replace:cdnUrl', 'replace:version', 'concat:config'], function () {
// 清除, 编译 / 处理项目中产生的文件
del([`${distPath}/static`, `${versionPath}/static/config`])
})
});

@ -17,11 +17,10 @@
"babel-plugin-component": "0.10.1", "babel-plugin-component": "0.10.1",
"babel-polyfill": "6.26.0", "babel-polyfill": "6.26.0",
"element-ui": "2.8.2", "element-ui": "2.8.2",
"gulp": "3.9.1", "gulp": "4.0.2",
"gulp-concat": "2.6.1", "gulp-concat": "2.6.1",
"gulp-load-plugins": "1.5.0", "gulp-load-plugins": "1.6.0",
"gulp-replace": "0.6.1", "gulp-replace": "1.0.0",
"gulp-shell": "0.6.5",
"lodash": "4.17.5", "lodash": "4.17.5",
"node-sass": "~4.12.0", "node-sass": "~4.12.0",
"sass-loader": "6.0.6", "sass-loader": "6.0.6",

Loading…
Cancel
Save