前端工程gulp 升级到4.0后 gulpfile.js修改 及工程打包,部署到nginx报错

提问 1 943
xduoo
xduoo 2020-10-23
版本:renren-fast 开发环境:vs code
前端工程gulp 升级到4.0后, gulpfile.js修改 为 [pre] var gulp = require('gulp'); var $ = require('gulp-load-plugins')(); var path = require('path'); var del = require('del'); var distPath = path.resolve('./dist'); var version = ''; // 版本号 var versionPath = ''; // 版本号路径 var env = ''; // 运行环境 // 创建版本号(年月日时分) (function () { var d = new Date(); var yy = d.getFullYear().toString().slice(2); var MM = d.getMonth() + 1 >= 10 ? (d.getMonth() + 1) : '0' + (d.getMonth() + 1); var DD = d.getDate() >= 10 ? d.getDate() : '0' + d.getDate(); var h = d.getHours() >= 10 ? d.getHours() : '0' + d.getHours(); var 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', gulp.series('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', gulp.series('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', gulp.series('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', gulp.series('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 () { // 获取环境配置 env = process.env.npm_config_qa ? 'qa' : process.env.npm_config_uat ? 'uat' : 'prod' console.log("clean complete!!") return del([versionPath]) }); gulp.task('default', gulp.series('clean', 'build', 'create:versionCatalog', 'replace:cdnUrl', 'replace:version', 'concat:config', function (done) { // 清除, 编译 / 处理项目中产生的文件 del([`${distPath}/static`, `${versionPath}/static/config`]) done() }) ); [/pre] 打包后dist文件: img[//cdn.renren.io/a7fcc202010231714182975.png] 部署nginx报错信息: img[//cdn.renren.io/bf8b4202010231714441702.png]
回帖
  • 再更新一下代码,测了一下,没有问题
    0 回复