第一次提交
This commit is contained in:
55
jeecgboot-vue3/build/script/buildConf.ts
Normal file
55
jeecgboot-vue3/build/script/buildConf.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* 生成外部配置文件,用于生产发布后配置,无需重新打包
|
||||
*/
|
||||
import { GLOB_CONFIG_FILE_NAME, OUTPUT_DIR } from '../constant';
|
||||
import fs, { writeFileSync } from 'fs-extra';
|
||||
import colors from 'picocolors';
|
||||
|
||||
import { getEnvConfig, getRootPath } from '../utils';
|
||||
import { getConfigFileName } from '../getConfigFileName';
|
||||
|
||||
import pkg from '../../package.json';
|
||||
|
||||
interface CreateConfigParams {
|
||||
configName: string;
|
||||
config: any;
|
||||
configFileName?: string;
|
||||
}
|
||||
|
||||
function createConfig(params: CreateConfigParams) {
|
||||
const { configName, config, configFileName } = params;
|
||||
try {
|
||||
const windowConf = `window.${configName}`;
|
||||
// Ensure that the variable will not be modified
|
||||
let configStr = `${windowConf}=${JSON.stringify(config)};`;
|
||||
configStr += `
|
||||
Object.freeze(${windowConf});
|
||||
Object.defineProperty(window, "${configName}", {
|
||||
configurable: false,
|
||||
writable: false,
|
||||
});
|
||||
`.replace(/\s/g, '');
|
||||
|
||||
fs.mkdirp(getRootPath(OUTPUT_DIR));
|
||||
writeFileSync(getRootPath(`${OUTPUT_DIR}/${configFileName}`), configStr);
|
||||
|
||||
console.log(colors.cyan(`✨ [${pkg.name}]`) + ` - configuration file is build successfully:`);
|
||||
console.log(colors.gray(OUTPUT_DIR + '/' + colors.green(configFileName)) + '\n');
|
||||
|
||||
// 如果是 Electron 环境,还需要将配置文件写入到 JSON 文件中
|
||||
if (config.VITE_GLOB_RUN_PLATFORM === 'electron') {
|
||||
writeFileSync(getRootPath(`${OUTPUT_DIR}/electron/env.json`), JSON.stringify(config));
|
||||
console.log(colors.cyan(`✨ [${pkg.name}]`) + ` - electron env file is build successfully:`);
|
||||
console.log(colors.gray(OUTPUT_DIR + '/' + colors.green('electron/env.json')) + '\n');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.log(colors.red('configuration file configuration file failed to package:\n' + error));
|
||||
}
|
||||
}
|
||||
|
||||
export function runBuildConfig() {
|
||||
const config = getEnvConfig();
|
||||
const configFileName = getConfigFileName(config);
|
||||
createConfig({ config, configName: configFileName, configFileName: GLOB_CONFIG_FILE_NAME });
|
||||
}
|
||||
14
jeecgboot-vue3/build/script/copyChat.ts
Normal file
14
jeecgboot-vue3/build/script/copyChat.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
|
||||
const sourceDir = path.join(__dirname, '../../src/views/super/airag/aiapp/chat/js'); // 源目录
|
||||
const destDir = path.join(__dirname, '../../dist', 'chat'); // 目标目录
|
||||
|
||||
// 复制目录
|
||||
fs.copy(sourceDir, destDir)
|
||||
.then(() => {
|
||||
console.log(`成功将 ${sourceDir} 复制到 ${destDir}`);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(`复制目录失败: ${err.message}`);
|
||||
});
|
||||
23
jeecgboot-vue3/build/script/postBuild.ts
Normal file
23
jeecgboot-vue3/build/script/postBuild.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
// #!/usr/bin/env node
|
||||
|
||||
import { runBuildConfig } from './buildConf';
|
||||
import colors from 'picocolors';
|
||||
|
||||
import pkg from '../../package.json';
|
||||
|
||||
export const runBuild = async () => {
|
||||
try {
|
||||
const argvList = process.argv.splice(2);
|
||||
|
||||
// Generate configuration file
|
||||
if (!argvList.includes('disabled-config')) {
|
||||
runBuildConfig();
|
||||
}
|
||||
|
||||
console.log(`✨ ${colors.cyan(`[${pkg.name}]`)}` + ' - build successfully!');
|
||||
} catch (error) {
|
||||
console.log(colors.red('vite build error:\n' + error));
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
runBuild();
|
||||
Reference in New Issue
Block a user