mirror of
https://gitee.com/bootx/dax-pay-ui.git
synced 2025-09-08 21:27:57 +00:00
fix(build): fix environment variable configuration file failure
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
import { GLOB_CONFIG_FILE_NAME } from '../constant';
|
||||
import fs, { writeFileSync } from 'fs-extra';
|
||||
|
||||
import viteConfig from '../../vite.config';
|
||||
import { errorConsole, successConsole, getCwdPath, getEnvConfig } from '../utils';
|
||||
import { getShortName } from '../getShortName';
|
||||
|
||||
@@ -17,7 +16,7 @@ function createConfig(
|
||||
) {
|
||||
try {
|
||||
const windowConf = `window.${configName}`;
|
||||
const outDir = viteConfig.outDir || 'dist';
|
||||
const outDir = 'dist';
|
||||
// Ensure that the variable will not be modified
|
||||
const configStr = `${windowConf}=${JSON.stringify(config)};
|
||||
|
||||
|
@@ -1,32 +1,20 @@
|
||||
// #!/usr/bin/env node
|
||||
|
||||
import { sh } from 'tasksfile';
|
||||
|
||||
import { argv } from 'yargs';
|
||||
import { runBuildConfig } from './buildConf';
|
||||
// import { runUpdateHtml } from './updateHtml';
|
||||
import { errorConsole, successConsole } from '../utils';
|
||||
import { startGzipStyle } from '../vite/plugin/gzip/compress';
|
||||
|
||||
export const runBuild = async (preview = false) => {
|
||||
export const runBuild = async () => {
|
||||
try {
|
||||
const argvList = argv._;
|
||||
if (preview) {
|
||||
let cmd = `cross-env NODE_ENV=production vite build`;
|
||||
await sh(cmd, {
|
||||
async: true,
|
||||
nopipe: true,
|
||||
});
|
||||
}
|
||||
|
||||
// Generate configuration file
|
||||
if (!argvList.includes('no-conf')) {
|
||||
await runBuildConfig();
|
||||
}
|
||||
// await runUpdateHtml();
|
||||
if (!preview) {
|
||||
await startGzipStyle();
|
||||
}
|
||||
await startGzipStyle();
|
||||
successConsole('Vite Build successfully!');
|
||||
} catch (error) {
|
||||
errorConsole('Vite Build Error\n' + error);
|
||||
|
@@ -1,74 +0,0 @@
|
||||
// Do you need to update the dependencies to prevent package.json from updating the dependencies, and no install after others get the code
|
||||
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import { isEqual } from 'lodash';
|
||||
import { sh } from 'tasksfile';
|
||||
import { successConsole, errorConsole } from '../utils';
|
||||
|
||||
const resolve = (dir: string) => {
|
||||
return path.resolve(process.cwd(), dir);
|
||||
};
|
||||
|
||||
const reg = /[\u4E00-\u9FA5\uF900-\uFA2D]/;
|
||||
|
||||
let NEED_INSTALL = false;
|
||||
|
||||
export async function runPreserve() {
|
||||
// rc.6 fixed
|
||||
const cwdPath = process.cwd();
|
||||
if (reg.test(cwdPath)) {
|
||||
errorConsole(
|
||||
'Do not include Chinese, Japanese or Korean in the full path of the project directory, please modify the directory name and run again!'
|
||||
);
|
||||
errorConsole('项目目录全路径请勿包含中文、日文、韩文,请修改目录名后再次重新运行!');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await fs.mkdirp(resolve('build/.cache'));
|
||||
function checkPkgUpdate() {
|
||||
const pkg = require('../../package.json');
|
||||
const { dependencies, devDependencies } = pkg;
|
||||
const depsFile = resolve('build/.cache/deps.json');
|
||||
if (!fs.pathExistsSync(depsFile)) {
|
||||
NEED_INSTALL = true;
|
||||
return;
|
||||
}
|
||||
const depsJson = require('../.cache/deps.json');
|
||||
|
||||
if (!isEqual(depsJson, { dependencies, devDependencies })) {
|
||||
NEED_INSTALL = true;
|
||||
}
|
||||
}
|
||||
checkPkgUpdate();
|
||||
if (NEED_INSTALL) {
|
||||
// no error
|
||||
successConsole(
|
||||
'A dependency change is detected, and the dependency is being installed to ensure that the dependency is consistent! (Tip: The project will be executed for the first time)!'
|
||||
);
|
||||
try {
|
||||
await sh('npm run bootstrap ', {
|
||||
async: true,
|
||||
nopipe: true,
|
||||
});
|
||||
|
||||
successConsole('Dependency installation is successful, start running the project!');
|
||||
|
||||
const pkg = require('../../package.json');
|
||||
const { dependencies, devDependencies } = pkg;
|
||||
const depsFile = resolve('build/.cache/deps.json');
|
||||
const deps = { dependencies, devDependencies };
|
||||
if (!fs.pathExistsSync(depsFile)) {
|
||||
fs.writeFileSync(depsFile, JSON.stringify(deps));
|
||||
} else {
|
||||
const depsFile = resolve('build/.cache/deps.json');
|
||||
const depsJson = require('../.cache/deps.json');
|
||||
if (!isEqual(depsJson, deps)) {
|
||||
fs.writeFileSync(depsFile, JSON.stringify(deps));
|
||||
}
|
||||
}
|
||||
} catch (error) {}
|
||||
}
|
||||
}
|
||||
|
||||
runPreserve();
|
@@ -4,12 +4,7 @@ import Koa from 'koa';
|
||||
import staticServer from 'koa-static';
|
||||
import portfinder from 'portfinder';
|
||||
import { resolve } from 'path';
|
||||
import viteConfig from '../../vite.config';
|
||||
import { getIPAddress } from '../utils';
|
||||
// import { runBuild } from './postBuild';
|
||||
|
||||
// const BUILD = 1;
|
||||
// const NO_BUILD = 2;
|
||||
|
||||
// start server
|
||||
const startApp = () => {
|
||||
@@ -17,7 +12,7 @@ const startApp = () => {
|
||||
portfinder.basePort = port;
|
||||
const app = new Koa();
|
||||
|
||||
app.use(staticServer(resolve(process.cwd(), viteConfig.outDir || 'dist')));
|
||||
app.use(staticServer(resolve(process.cwd(), 'dist')));
|
||||
|
||||
portfinder.getPort(async (err, port) => {
|
||||
if (err) {
|
||||
@@ -35,25 +30,4 @@ const startApp = () => {
|
||||
});
|
||||
};
|
||||
|
||||
// export const runPreview = async () => {
|
||||
// // const prompt = inquirer.prompt({
|
||||
// // type: 'list',
|
||||
// // message: 'Please select a preview method',
|
||||
// // name: 'type',
|
||||
// // choices: [
|
||||
// // {
|
||||
// // name: 'Preview after packaging',
|
||||
// // value: BUILD,
|
||||
// // },
|
||||
// // {
|
||||
// // name: `No packaging, preview directly (need to have dist file after packaging)`,
|
||||
// // value: NO_BUILD,
|
||||
// // },
|
||||
// // ],
|
||||
// // });
|
||||
// const { type } = await prompt;
|
||||
// if (type === BUILD) {
|
||||
// await runBuild(true);
|
||||
// }
|
||||
// };
|
||||
startApp();
|
||||
|
Reference in New Issue
Block a user