修改打包方式

This commit is contained in:
YeMingfei666 2024-12-26 17:37:28 +08:00
parent 139f198ad5
commit f256740dcb
1 changed files with 14 additions and 14 deletions

View File

@ -32,14 +32,14 @@ gulp.task('create:versionCatalog', gulp.series('build', function () {
// 替换${versionPath}/static/js/manifest.js window.SITE_CONFIG.cdnUrl占位变量 // 替换${versionPath}/static/js/manifest.js window.SITE_CONFIG.cdnUrl占位变量
gulp.task('replace:cdnUrl', gulp.series('create:versionCatalog', function () { gulp.task('replace:cdnUrl', gulp.series('create:versionCatalog', function () {
return gulp.src(`${versionPath}/static/js/manifest.js`) return gulp.src(`${versionPath}/static/js/manifest.js`)
.pipe($.replace(new RegExp(`"${require('./config').build.assetsPublicPath}"`, 'g'), 'window.SITE_CONFIG.cdnUrl + "/"')) .pipe($.revReplace(new RegExp(`"${require('./config').build.assetsPublicPath}"`, 'g'), 'window.SITE_CONFIG.cdnUrl + "/"'))
.pipe(gulp.dest(`${versionPath}/static/js/`)) .pipe(gulp.dest(`${versionPath}/static/js/`))
})) }))
// 替换${versionPath}/static/config/index-${env}.js window.SITE_CONFIG['version']配置变量 // 替换${versionPath}/static/config/index-${env}.js window.SITE_CONFIG['version']配置变量
gulp.task('replace:version', gulp.series('create:versionCatalog', function () { gulp.task('replace:version', gulp.series('create:versionCatalog', function () {
return gulp.src(`${versionPath}/static/config/index-${env}.js`) return gulp.src(`${versionPath}/static/config/index-${env}.js`)
.pipe($.replace(/window.SITE_CONFIG\['version'\] = '.*'/g, `window.SITE_CONFIG['version'] = '${version}'`)) .pipe($.revReplace(/window.SITE_CONFIG\['version'\] = '.*'/g, `window.SITE_CONFIG['version'] = '${version}'`))
.pipe(gulp.dest(`${versionPath}/static/config/`)) .pipe(gulp.dest(`${versionPath}/static/config/`))
})) }))
@ -61,7 +61,7 @@ gulp.task('clean', function () {
gulp.task('build-end', function () { gulp.task('build-end', function () {
console.log('--builed-end--') console.log('--builed-end--')
// del([`${distPath}/static`, `${versionPath}/static/config`]); // del([`${distPath}/static`, `${versionPath}/static/config`]);
return del([`${distPath}/static`, `${versionPath}/static/config`]); return del([`${distPath}/static`, `${versionPath}/static/config`]);
}) })
env = process.env.npm_config_qa ? 'qa' : process.env.npm_config_uat ? 'uat' : 'prod'; env = process.env.npm_config_qa ? 'qa' : process.env.npm_config_uat ? 'uat' : 'prod';
@ -69,7 +69,7 @@ env = process.env.npm_config_qa ? 'qa' : process.env.npm_config_uat ? 'uat' : 'p
gulp.task('default', gulp.task('default',
gulp.series('clean', gulp.series('clean',
gulp.parallel('create:versionCatalog', 'replace:cdnUrl', 'replace:version', 'concat:config'), gulp.parallel('create:versionCatalog', 'replace:cdnUrl', 'replace:version', 'concat:config'),
'build','build-end') 'build', 'build-end')
) )
@ -81,22 +81,22 @@ gulp.task('default',
// 开始打包编译 // 开始打包编译
// 开始打包编译 // 开始打包编译
gulp.task('default', gulp.series('build','create:versionCatalog', 'replace:cdnUrl', 'replace:version', 'concat:config', function (done) { gulp.task('default', gulp.series('build','create:versionCatalog', 'replace:cdnUrl', 'replace:version', 'concat:config', function (done) {
// 清除, 编译 / 处理项目中产生的文件 // 清除, 编译 / 处理项目中产生的文件
del([`${distPath}/static`, `${versionPath}/static/config`]) del([`${distPath}/static`, `${versionPath}/static/config`])
done(); done();
})) }))
})); */ })); */
/* /*
gulp.task('default', gulp.series('clean', function (done) { gulp.task('default', gulp.series('clean', function (done) {
// 获取环境配置 // 获取环境配置
env = process.env.npm_config_qa ? 'qa' : process.env.npm_config_uat ? 'uat' : 'prod' env = process.env.npm_config_qa ? 'qa' : process.env.npm_config_uat ? 'uat' : 'prod'
// 开始打包编译 // 开始打包编译
// 开始打包编译 // 开始打包编译
gulp.task('default', gulp.series('build','create:versionCatalog', 'replace:cdnUrl', 'replace:version', 'concat:config', function (done) { gulp.task('default', gulp.series('build','create:versionCatalog', 'replace:cdnUrl', 'replace:version', 'concat:config', function (done) {
// 清除, 编译 / 处理项目中产生的文件 // 清除, 编译 / 处理项目中产生的文件
del([`${distPath}/static`, `${versionPath}/static/config`]) del([`${distPath}/static`, `${versionPath}/static/config`])
done(); done();
})) }))
})); }));
*/ */