mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-26 08:36:19 +08:00
style: add some notes
This commit is contained in:
@@ -1 +1,4 @@
|
||||
/**
|
||||
* The name of the configuration file entered in the production environment
|
||||
*/
|
||||
export const GLOB_CONFIG_FILE_NAME = '_app.config.js';
|
||||
|
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Get the configuration file variable name
|
||||
* @param env
|
||||
*/
|
||||
export const getShortName = (env: any) => {
|
||||
return `__PRODUCTION__${env.VITE_GLOB_APP_SHORT_NAME || '__APP'}__CONF__`
|
||||
.toUpperCase()
|
||||
|
@@ -1,14 +1,12 @@
|
||||
/**
|
||||
* Generate additional configuration files when used for packaging. The file can be configured with some global variables, so that it can be changed directly externally without repackaging
|
||||
*/
|
||||
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';
|
||||
|
||||
const getShortName = (env: any) => {
|
||||
return `__PRODUCTION__${env.VITE_GLOB_APP_SHORT_NAME || '__APP'}__CONF__`
|
||||
.toUpperCase()
|
||||
.replace(/\s/g, '');
|
||||
};
|
||||
import { getShortName } from '../getShortName';
|
||||
|
||||
function createConfig(
|
||||
{
|
||||
@@ -20,6 +18,7 @@ function createConfig(
|
||||
try {
|
||||
const windowConf = `window.${configName}`;
|
||||
const outDir = viteConfig.outDir || 'dist';
|
||||
// Ensure that the variable will not be modified
|
||||
const configStr = `${windowConf}=${JSON.stringify(config)};
|
||||
|
||||
Object.freeze(${windowConf});
|
||||
|
@@ -7,6 +7,7 @@ import chalk from 'chalk';
|
||||
|
||||
export const isFunction = (arg: unknown): arg is (...args: any[]) => any =>
|
||||
typeof arg === 'function';
|
||||
|
||||
export const isRegExp = (arg: unknown): arg is RegExp =>
|
||||
Object.prototype.toString.call(arg) === '[object RegExp]';
|
||||
|
||||
@@ -43,6 +44,9 @@ export function readAllFile(root: string, reg: RegExp) {
|
||||
return resultArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* get client ip address
|
||||
*/
|
||||
export function getIPAddress() {
|
||||
let interfaces = networkInterfaces();
|
||||
for (let devName in interfaces) {
|
||||
@@ -67,12 +71,23 @@ export function isProdFn(): boolean {
|
||||
return process.env.NODE_ENV === 'production';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to generate package preview
|
||||
*/
|
||||
export function isReportMode(): boolean {
|
||||
return process.env.REPORT === 'true';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to generate gzip for packaging
|
||||
*/
|
||||
export function isBuildGzip(): boolean {
|
||||
return process.env.VITE_BUILD_GZIP === 'true';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to generate package site
|
||||
*/
|
||||
export function isSiteMode(): boolean {
|
||||
return process.env.SITE === 'true';
|
||||
}
|
||||
@@ -89,6 +104,7 @@ export interface ViteEnv {
|
||||
VITE_BUILD_GZIP: boolean;
|
||||
}
|
||||
|
||||
// Read all environment variable configuration files to process.env
|
||||
export function loadEnv(): ViteEnv {
|
||||
const env = process.env.NODE_ENV;
|
||||
const ret: any = {};
|
||||
@@ -116,6 +132,11 @@ export function loadEnv(): ViteEnv {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the environment variables starting with the specified prefix
|
||||
* @param match prefix
|
||||
* @param confFiles ext
|
||||
*/
|
||||
export function getEnvConfig(match = 'VITE_GLOB_', confFiles = ['.env', '.env.production']) {
|
||||
let envConfig = {};
|
||||
confFiles.forEach((item) => {
|
||||
@@ -142,18 +163,34 @@ function consoleFn(color: string, message: any) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* warnConsole
|
||||
* @param message
|
||||
*/
|
||||
export function successConsole(message: any) {
|
||||
consoleFn('green', '✨ ' + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* warnConsole
|
||||
* @param message
|
||||
*/
|
||||
export function errorConsole(message: any) {
|
||||
consoleFn('red', '✨ ' + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* warnConsole
|
||||
* @param message message
|
||||
*/
|
||||
export function warnConsole(message: any) {
|
||||
consoleFn('yellow', '✨ ' + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user root directory
|
||||
* @param dir file path
|
||||
*/
|
||||
export function getCwdPath(...dir: string[]) {
|
||||
return path.resolve(process.cwd(), ...dir);
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
// 百度统计代码 用于站点部署
|
||||
// 只在build:site开启
|
||||
// Baidu statistics code for site deployment
|
||||
// Only open in build:site
|
||||
export const hmScript = `<script>
|
||||
var _hmt = _hmt || [];
|
||||
(function() {
|
||||
|
@@ -1,6 +1,7 @@
|
||||
// 修改自https://github.com/kryops/rollup-plugin-gzip
|
||||
// 因为rollup-plugin-gzip不支持vite
|
||||
// vite对css打包独立的。所以不能在打包的时候顺带打包css
|
||||
// TODO rc.9会支持 configurBuild 配置项。到时候重新修改
|
||||
|
||||
import { readFile, writeFile } from 'fs';
|
||||
import { basename } from 'path';
|
||||
|
@@ -3,6 +3,11 @@ type ProxyItem = [string, string];
|
||||
type ProxyList = ProxyItem[];
|
||||
|
||||
const reg = /^https:\/\//;
|
||||
|
||||
/**
|
||||
* Generate proxy
|
||||
* @param list
|
||||
*/
|
||||
export function createProxy(list: ProxyList = []) {
|
||||
const ret: any = {};
|
||||
for (const [prefix, target] of list) {
|
||||
@@ -12,6 +17,7 @@ export function createProxy(list: ProxyList = []) {
|
||||
target: target,
|
||||
changeOrigin: true,
|
||||
rewrite: (path: string) => path.replace(new RegExp(`^${prefix}`), ''),
|
||||
// https is require secure=false
|
||||
...(isHttps ? { secure: false } : {}),
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user