mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-06-06 00:10:23 +08:00
optimize vben/build
This commit is contained in:
@@ -1,33 +1,33 @@
|
||||
import { generate } from '@ant-design/colors';
|
||||
import { generate } from '@ant-design/colors'
|
||||
|
||||
export const primaryColor = '#0960bd';
|
||||
export const primaryColor = '#0960bd'
|
||||
|
||||
export const darkMode = 'light';
|
||||
export const darkMode = 'light'
|
||||
|
||||
type Fn = (...arg: any) => any;
|
||||
type Fn = (...arg: any) => any
|
||||
|
||||
type GenerateTheme = 'default' | 'dark';
|
||||
type GenerateTheme = 'default' | 'dark'
|
||||
|
||||
export interface GenerateColorsParams {
|
||||
mixLighten: Fn;
|
||||
mixDarken: Fn;
|
||||
tinycolor: any;
|
||||
color?: string;
|
||||
mixLighten: Fn
|
||||
mixDarken: Fn
|
||||
tinycolor: any
|
||||
color?: string
|
||||
}
|
||||
|
||||
export function generateAntColors(color: string, theme: GenerateTheme = 'default') {
|
||||
return generate(color, {
|
||||
theme,
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
export function getThemeColors(color?: string) {
|
||||
const tc = color || primaryColor;
|
||||
const lightColors = generateAntColors(tc);
|
||||
const primary = lightColors[5];
|
||||
const modeColors = generateAntColors(primary, 'dark');
|
||||
const tc = color || primaryColor
|
||||
const lightColors = generateAntColors(tc)
|
||||
const primary = lightColors[5]
|
||||
const modeColors = generateAntColors(primary, 'dark')
|
||||
|
||||
return [...lightColors, ...modeColors];
|
||||
return [...lightColors, ...modeColors]
|
||||
}
|
||||
|
||||
export function generateColors({
|
||||
@@ -36,38 +36,38 @@ export function generateColors({
|
||||
mixDarken,
|
||||
tinycolor,
|
||||
}: GenerateColorsParams) {
|
||||
const arr = new Array(19).fill(0);
|
||||
const arr = new Array(19).fill(0)
|
||||
const lightens = arr.map((_t, i) => {
|
||||
return mixLighten(color, i / 5);
|
||||
});
|
||||
return mixLighten(color, i / 5)
|
||||
})
|
||||
|
||||
const darkens = arr.map((_t, i) => {
|
||||
return mixDarken(color, i / 5);
|
||||
});
|
||||
return mixDarken(color, i / 5)
|
||||
})
|
||||
|
||||
const alphaColors = arr.map((_t, i) => {
|
||||
return tinycolor(color)
|
||||
.setAlpha(i / 20)
|
||||
.toRgbString();
|
||||
});
|
||||
.toRgbString()
|
||||
})
|
||||
|
||||
const shortAlphaColors = alphaColors.map((item) => item.replace(/\s/g, '').replace(/0\./g, '.'));
|
||||
const shortAlphaColors = alphaColors.map((item) => item.replace(/\s/g, '').replace(/0\./g, '.'))
|
||||
|
||||
const tinycolorLightens = arr
|
||||
.map((_t, i) => {
|
||||
return tinycolor(color)
|
||||
.lighten(i * 5)
|
||||
.toHexString();
|
||||
.toHexString()
|
||||
})
|
||||
.filter((item) => item !== '#ffffff');
|
||||
.filter((item) => item !== '#ffffff')
|
||||
|
||||
const tinycolorDarkens = arr
|
||||
.map((_t, i) => {
|
||||
return tinycolor(color)
|
||||
.darken(i * 5)
|
||||
.toHexString();
|
||||
.toHexString()
|
||||
})
|
||||
.filter((item) => item !== '#000000');
|
||||
.filter((item) => item !== '#000000')
|
||||
return [
|
||||
...lightens,
|
||||
...darkens,
|
||||
@@ -75,5 +75,5 @@ export function generateColors({
|
||||
...shortAlphaColors,
|
||||
...tinycolorDarkens,
|
||||
...tinycolorLightens,
|
||||
].filter((item) => !item.includes('-'));
|
||||
].filter((item) => !item.includes('-'))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The name of the configuration file entered in the production environment
|
||||
*/
|
||||
export const GLOB_CONFIG_FILE_NAME = '_app.config.js';
|
||||
export const GLOB_CONFIG_FILE_NAME = '_app.config.js'
|
||||
|
||||
export const OUTPUT_DIR = 'dist';
|
||||
export const OUTPUT_DIR = 'dist'
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import { generateAntColors, primaryColor } from '../config/themeConfig';
|
||||
import { getThemeVariables } from 'ant-design-vue/dist/theme';
|
||||
import { resolve } from 'path';
|
||||
import { generateAntColors, primaryColor } from '../config/themeConfig'
|
||||
import { getThemeVariables } from 'ant-design-vue/dist/theme'
|
||||
import { resolve } from 'path'
|
||||
|
||||
/**
|
||||
* less global variable
|
||||
*/
|
||||
export function generateModifyVars(dark = false) {
|
||||
const palettes = generateAntColors(primaryColor);
|
||||
const primary = palettes[5];
|
||||
const palettes = generateAntColors(primaryColor)
|
||||
const primary = palettes[5]
|
||||
|
||||
const primaryColorObj: Record<string, string> = {};
|
||||
const primaryColorObj: Record<string, string> = {}
|
||||
|
||||
for (let index = 0; index < 10; index++) {
|
||||
primaryColorObj[`primary-${index + 1}`] = palettes[index];
|
||||
primaryColorObj[`primary-${index + 1}`] = palettes[index]
|
||||
}
|
||||
|
||||
const modifyVars = getThemeVariables({ dark });
|
||||
const modifyVars = getThemeVariables({ dark })
|
||||
return {
|
||||
...modifyVars,
|
||||
// Used for global import to avoid the need to import each style file separately
|
||||
@@ -33,5 +33,5 @@ export function generateModifyVars(dark = false) {
|
||||
'border-radius-base': '2px', // Component/float fillet
|
||||
'link-color': primary, // Link color
|
||||
'app-content-background': '#fafafa', // Link color
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import inquirer from 'inquirer';
|
||||
import colors from 'picocolors';
|
||||
import pkg from '../../../package.json';
|
||||
import path from 'path'
|
||||
import fs from 'fs-extra'
|
||||
import inquirer from 'inquirer'
|
||||
import colors from 'picocolors'
|
||||
import pkg from '../../../package.json'
|
||||
|
||||
async function generateIcon() {
|
||||
const dir = path.resolve(process.cwd(), 'node_modules/@iconify/json');
|
||||
const dir = path.resolve(process.cwd(), 'node_modules/@iconify/json')
|
||||
|
||||
const raw = await fs.readJSON(path.join(dir, 'collections.json'));
|
||||
const raw = await fs.readJSON(path.join(dir, 'collections.json'))
|
||||
|
||||
const collections = Object.entries(raw).map(([id, v]) => ({
|
||||
...(v as any),
|
||||
id,
|
||||
}));
|
||||
}))
|
||||
|
||||
const choices = collections.map((item) => ({ key: item.id, value: item.id, name: item.name }));
|
||||
const choices = collections.map((item) => ({ key: item.id, value: item.id, name: item.name }))
|
||||
|
||||
inquirer
|
||||
.prompt([
|
||||
@@ -41,32 +41,32 @@ async function generateIcon() {
|
||||
},
|
||||
])
|
||||
.then(async (answers) => {
|
||||
const { iconSet, output, useType } = answers;
|
||||
const outputDir = path.resolve(process.cwd(), output);
|
||||
fs.ensureDir(outputDir);
|
||||
const genCollections = collections.filter((item) => [iconSet].includes(item.id));
|
||||
const prefixSet: string[] = [];
|
||||
const { iconSet, output, useType } = answers
|
||||
const outputDir = path.resolve(process.cwd(), output)
|
||||
fs.ensureDir(outputDir)
|
||||
const genCollections = collections.filter((item) => [iconSet].includes(item.id))
|
||||
const prefixSet: string[] = []
|
||||
for (const info of genCollections) {
|
||||
const data = await fs.readJSON(path.join(dir, 'json', `${info.id}.json`));
|
||||
const data = await fs.readJSON(path.join(dir, 'json', `${info.id}.json`))
|
||||
if (data) {
|
||||
const { prefix } = data;
|
||||
const isLocal = useType === 'local';
|
||||
const { prefix } = data
|
||||
const isLocal = useType === 'local'
|
||||
const icons = Object.keys(data.icons).map(
|
||||
(item) => `${isLocal ? prefix + ':' : ''}${item}`,
|
||||
);
|
||||
)
|
||||
|
||||
await fs.writeFileSync(
|
||||
path.join(output, `icons.data.ts`),
|
||||
`export default ${isLocal ? JSON.stringify(icons) : JSON.stringify({ prefix, icons })}`,
|
||||
);
|
||||
prefixSet.push(prefix);
|
||||
)
|
||||
prefixSet.push(prefix)
|
||||
}
|
||||
}
|
||||
fs.emptyDir(path.join(process.cwd(), 'node_modules/.vite'));
|
||||
fs.emptyDir(path.join(process.cwd(), 'node_modules/.vite'))
|
||||
console.log(
|
||||
`✨ ${colors.cyan(`[${pkg.name}]`)}` + ' - Icon generated successfully:' + `[${prefixSet}]`,
|
||||
);
|
||||
});
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
generateIcon();
|
||||
generateIcon()
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
export const getConfigFileName = (env: Record<string, any>) => {
|
||||
return `__PRODUCTION__${env.VITE_GLOB_APP_SHORT_NAME || '__APP'}__CONF__`
|
||||
.toUpperCase()
|
||||
.replace(/\s/g, '');
|
||||
};
|
||||
.replace(/\s/g, '')
|
||||
}
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
/**
|
||||
* 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, OUTPUT_DIR } from '../constant';
|
||||
import fs, { writeFileSync } from 'fs-extra';
|
||||
import colors from 'picocolors';
|
||||
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 { getEnvConfig, getRootPath } from '../utils'
|
||||
import { getConfigFileName } from '../getConfigFileName'
|
||||
|
||||
import pkg from '../../package.json';
|
||||
import pkg from '../../package.json'
|
||||
|
||||
interface CreateConfigParams {
|
||||
configName: string;
|
||||
config: any;
|
||||
configFileName?: string;
|
||||
configName: string
|
||||
config: any
|
||||
configFileName?: string
|
||||
}
|
||||
|
||||
function createConfig(params: CreateConfigParams) {
|
||||
const { configName, config, configFileName } = params;
|
||||
const { configName, config, configFileName } = params
|
||||
try {
|
||||
const windowConf = `window.${configName}`;
|
||||
const windowConf = `window.${configName}`
|
||||
// Ensure that the variable will not be modified
|
||||
let configStr = `${windowConf}=${JSON.stringify(config)};`;
|
||||
let configStr = `${windowConf}=${JSON.stringify(config)};`
|
||||
configStr += `
|
||||
Object.freeze(${windowConf});
|
||||
Object.defineProperty(window, "${configName}", {
|
||||
configurable: false,
|
||||
writable: false,
|
||||
});
|
||||
`.replace(/\s/g, '');
|
||||
`.replace(/\s/g, '')
|
||||
|
||||
fs.mkdirp(getRootPath(OUTPUT_DIR));
|
||||
writeFileSync(getRootPath(`${OUTPUT_DIR}/${configFileName}`), configStr);
|
||||
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');
|
||||
console.log(colors.cyan(`✨ [${pkg.name}]`) + ` - configuration file is build successfully:`)
|
||||
console.log(colors.gray(OUTPUT_DIR + '/' + colors.green(configFileName)) + '\n')
|
||||
} catch (error) {
|
||||
console.log(colors.red('configuration file configuration file failed to package:\n' + 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 });
|
||||
const config = getEnvConfig()
|
||||
const configFileName = getConfigFileName(config)
|
||||
createConfig({ config, configName: configFileName, configFileName: GLOB_CONFIG_FILE_NAME })
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
// #!/usr/bin/env node
|
||||
|
||||
import { runBuildConfig } from './buildConf';
|
||||
import colors from 'picocolors';
|
||||
import { runBuildConfig } from './buildConf'
|
||||
import colors from 'picocolors'
|
||||
|
||||
import pkg from '../../package.json';
|
||||
import pkg from '../../package.json'
|
||||
|
||||
export const runBuild = async () => {
|
||||
try {
|
||||
const argvList = process.argv.splice(2);
|
||||
const argvList = process.argv.splice(2)
|
||||
|
||||
// Generate configuration file
|
||||
if (!argvList.includes('disabled-config')) {
|
||||
runBuildConfig();
|
||||
runBuildConfig()
|
||||
}
|
||||
|
||||
console.log(`✨ ${colors.cyan(`[${pkg.name}]`)}` + ' - build successfully!');
|
||||
console.log(`✨ ${colors.cyan(`[${pkg.name}]`)}` + ' - build successfully!')
|
||||
} catch (error) {
|
||||
console.log(colors.red('vite build error:\n' + error));
|
||||
process.exit(1);
|
||||
console.log(colors.red('vite build error:\n' + error))
|
||||
process.exit(1)
|
||||
}
|
||||
};
|
||||
runBuild();
|
||||
}
|
||||
runBuild()
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import dotenv from 'dotenv';
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import dotenv from 'dotenv'
|
||||
|
||||
export function isDevFn(mode: string): boolean {
|
||||
return mode === 'development';
|
||||
return mode === 'development'
|
||||
}
|
||||
|
||||
export function isProdFn(mode: string): boolean {
|
||||
return mode === 'production';
|
||||
return mode === 'production'
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to generate package preview
|
||||
*/
|
||||
export function isReportMode(): boolean {
|
||||
return process.env.REPORT === 'true';
|
||||
return process.env.REPORT === 'true'
|
||||
}
|
||||
|
||||
// Read all environment variable configuration files to process.env
|
||||
export function wrapperEnv(envConf: Recordable): ViteEnv {
|
||||
const ret: any = {};
|
||||
const ret: any = {}
|
||||
|
||||
for (const envName of Object.keys(envConf)) {
|
||||
let realName = envConf[envName].replace(/\\n/g, '\n');
|
||||
realName = realName === 'true' ? true : realName === 'false' ? false : realName;
|
||||
let realName = envConf[envName].replace(/\\n/g, '\n')
|
||||
realName = realName === 'true' ? true : realName === 'false' ? false : realName
|
||||
|
||||
if (envName === 'VITE_PORT') {
|
||||
realName = Number(realName);
|
||||
realName = Number(realName)
|
||||
}
|
||||
if (envName === 'VITE_PROXY' && realName) {
|
||||
try {
|
||||
realName = JSON.parse(realName.replace(/'/g, '"'));
|
||||
realName = JSON.parse(realName.replace(/'/g, '"'))
|
||||
} catch (error) {
|
||||
realName = '';
|
||||
realName = ''
|
||||
}
|
||||
}
|
||||
ret[envName] = realName;
|
||||
ret[envName] = realName
|
||||
if (typeof realName === 'string') {
|
||||
process.env[envName] = realName;
|
||||
process.env[envName] = realName
|
||||
} else if (typeof realName === 'object') {
|
||||
process.env[envName] = JSON.stringify(realName);
|
||||
process.env[envName] = JSON.stringify(realName)
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return ret
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前环境下生效的配置文件名
|
||||
*/
|
||||
function getConfFiles() {
|
||||
const script = process.env.npm_lifecycle_script;
|
||||
const reg = new RegExp('--mode ([a-z_\\d]+)');
|
||||
const result = reg.exec(script as string) as any;
|
||||
const script = process.env.npm_lifecycle_script
|
||||
const reg = new RegExp('--mode ([a-z_\\d]+)')
|
||||
const result = reg.exec(script as string) as any
|
||||
if (result) {
|
||||
const mode = result[1] as string;
|
||||
return ['.env', `.env.${mode}`];
|
||||
const mode = result[1] as string
|
||||
return ['.env', `.env.${mode}`]
|
||||
}
|
||||
return ['.env', '.env.production'];
|
||||
return ['.env', '.env.production']
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,22 +65,22 @@ function getConfFiles() {
|
||||
* @param confFiles ext
|
||||
*/
|
||||
export function getEnvConfig(match = 'VITE_GLOB_', confFiles = getConfFiles()) {
|
||||
let envConfig = {};
|
||||
let envConfig = {}
|
||||
confFiles.forEach((item) => {
|
||||
try {
|
||||
const env = dotenv.parse(fs.readFileSync(path.resolve(process.cwd(), item)));
|
||||
envConfig = { ...envConfig, ...env };
|
||||
const env = dotenv.parse(fs.readFileSync(path.resolve(process.cwd(), item)))
|
||||
envConfig = { ...envConfig, ...env }
|
||||
} catch (e) {
|
||||
console.error(`Error in parsing ${item}`, e);
|
||||
console.error(`Error in parsing ${item}`, e)
|
||||
}
|
||||
});
|
||||
const reg = new RegExp(`^(${match})`);
|
||||
})
|
||||
const reg = new RegExp(`^(${match})`)
|
||||
Object.keys(envConfig).forEach((key) => {
|
||||
if (!reg.test(key)) {
|
||||
Reflect.deleteProperty(envConfig, key);
|
||||
Reflect.deleteProperty(envConfig, key)
|
||||
}
|
||||
});
|
||||
return envConfig;
|
||||
})
|
||||
return envConfig
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,5 +88,5 @@ export function getEnvConfig(match = 'VITE_GLOB_', confFiles = getConfFiles()) {
|
||||
* @param dir file path
|
||||
*/
|
||||
export function getRootPath(...dir: string[]) {
|
||||
return path.resolve(process.cwd(), ...dir);
|
||||
return path.resolve(process.cwd(), ...dir)
|
||||
}
|
||||
|
||||
@@ -2,16 +2,16 @@
|
||||
* Used to package and output gzip. Note that this does not work properly in Vite, the specific reason is still being investigated
|
||||
* https://github.com/anncwb/vite-plugin-compression
|
||||
*/
|
||||
import type { PluginOption } from 'vite';
|
||||
import compressPlugin from 'vite-plugin-compression';
|
||||
import type { PluginOption } from 'vite'
|
||||
import compressPlugin from 'vite-plugin-compression'
|
||||
|
||||
export function configCompressPlugin(
|
||||
compress: 'gzip' | 'brotli' | 'none',
|
||||
deleteOriginFile = false,
|
||||
): PluginOption | PluginOption[] {
|
||||
const compressList = compress.split(',');
|
||||
const compressList = compress.split(',')
|
||||
|
||||
const plugins: PluginOption[] = [];
|
||||
const plugins: PluginOption[] = []
|
||||
|
||||
if (compressList.includes('gzip')) {
|
||||
plugins.push(
|
||||
@@ -19,7 +19,7 @@ export function configCompressPlugin(
|
||||
ext: '.gz',
|
||||
deleteOriginFile,
|
||||
}),
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
if (compressList.includes('brotli')) {
|
||||
@@ -29,7 +29,7 @@ export function configCompressPlugin(
|
||||
algorithm: 'brotliCompress',
|
||||
deleteOriginFile,
|
||||
}),
|
||||
);
|
||||
)
|
||||
}
|
||||
return plugins;
|
||||
return plugins
|
||||
}
|
||||
|
||||
@@ -2,19 +2,19 @@
|
||||
* Plugin to minimize and use ejs template syntax in index.html.
|
||||
* https://github.com/anncwb/vite-plugin-html
|
||||
*/
|
||||
import type { PluginOption } from 'vite';
|
||||
import { createHtmlPlugin } from 'vite-plugin-html';
|
||||
import pkg from '../../../package.json';
|
||||
import { GLOB_CONFIG_FILE_NAME } from '../../constant';
|
||||
import type { PluginOption } from 'vite'
|
||||
import { createHtmlPlugin } from 'vite-plugin-html'
|
||||
import pkg from '../../../package.json'
|
||||
import { GLOB_CONFIG_FILE_NAME } from '../../constant'
|
||||
|
||||
export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) {
|
||||
const { VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH } = env;
|
||||
const { VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH } = env
|
||||
|
||||
const path = VITE_PUBLIC_PATH.endsWith('/') ? VITE_PUBLIC_PATH : `${VITE_PUBLIC_PATH}/`;
|
||||
const path = VITE_PUBLIC_PATH.endsWith('/') ? VITE_PUBLIC_PATH : `${VITE_PUBLIC_PATH}/`
|
||||
|
||||
const getAppConfigSrc = () => {
|
||||
return `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${pkg.version}-${new Date().getTime()}`;
|
||||
};
|
||||
return `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${pkg.version}-${new Date().getTime()}`
|
||||
}
|
||||
|
||||
const htmlPlugin: PluginOption[] = createHtmlPlugin({
|
||||
minify: isBuild,
|
||||
@@ -35,6 +35,6 @@ export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) {
|
||||
]
|
||||
: [],
|
||||
},
|
||||
});
|
||||
return htmlPlugin;
|
||||
})
|
||||
return htmlPlugin
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Image resource files used to compress the output of the production environment
|
||||
// https://github.com/anncwb/vite-plugin-imagemin
|
||||
import viteImagemin from 'vite-plugin-imagemin';
|
||||
import viteImagemin from 'vite-plugin-imagemin'
|
||||
|
||||
export function configImageminPlugin() {
|
||||
const plugin = viteImagemin({
|
||||
@@ -29,6 +29,6 @@ export function configImageminPlugin() {
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
return plugin;
|
||||
})
|
||||
return plugin
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* Mock plugin for development and production.
|
||||
* https://github.com/anncwb/vite-plugin-mock
|
||||
*/
|
||||
import { viteMockServe } from 'vite-plugin-mock';
|
||||
import { viteMockServe } from 'vite-plugin-mock'
|
||||
|
||||
export function configMockPlugin(isBuild: boolean) {
|
||||
return viteMockServe({
|
||||
@@ -15,5 +15,5 @@ export function configMockPlugin(isBuild: boolean) {
|
||||
|
||||
setupProdMockServer();
|
||||
`,
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
* Zero-config PWA for Vite
|
||||
* https://github.com/antfu/vite-plugin-pwa
|
||||
*/
|
||||
import { VitePWA } from 'vite-plugin-pwa';
|
||||
import { VitePWA } from 'vite-plugin-pwa'
|
||||
|
||||
export function configPwaConfig(env: ViteEnv) {
|
||||
const { VITE_USE_PWA, VITE_GLOB_APP_TITLE, VITE_GLOB_APP_SHORT_NAME } = env;
|
||||
const { VITE_USE_PWA, VITE_GLOB_APP_TITLE, VITE_GLOB_APP_SHORT_NAME } = env
|
||||
|
||||
if (VITE_USE_PWA) {
|
||||
// vite-plugin-pwa
|
||||
@@ -26,8 +26,8 @@ export function configPwaConfig(env: ViteEnv) {
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
return pwaPlugin;
|
||||
})
|
||||
return pwaPlugin
|
||||
}
|
||||
return [];
|
||||
return []
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
* https://github.com/anncwb/vite-plugin-svg-icons
|
||||
*/
|
||||
|
||||
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
|
||||
import path from 'path';
|
||||
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
|
||||
import path from 'path'
|
||||
|
||||
export function configSvgIconsPlugin(isBuild: boolean) {
|
||||
const svgIconsPlugin = createSvgIconsPlugin({
|
||||
@@ -12,6 +12,6 @@ export function configSvgIconsPlugin(isBuild: boolean) {
|
||||
svgoOptions: isBuild,
|
||||
// default
|
||||
symbolId: 'icon-[dir]-[name]',
|
||||
});
|
||||
return svgIconsPlugin;
|
||||
})
|
||||
return svgIconsPlugin
|
||||
}
|
||||
|
||||
@@ -2,46 +2,46 @@
|
||||
* Vite plugin for website theme color switching
|
||||
* https://github.com/anncwb/vite-plugin-theme
|
||||
*/
|
||||
import type { PluginOption } from 'vite';
|
||||
import path from 'path';
|
||||
import type { PluginOption } from 'vite'
|
||||
import path from 'path'
|
||||
import {
|
||||
viteThemePlugin,
|
||||
antdDarkThemePlugin,
|
||||
mixLighten,
|
||||
mixDarken,
|
||||
tinycolor,
|
||||
} from 'vite-plugin-theme';
|
||||
import { getThemeColors, generateColors } from '../../config/themeConfig';
|
||||
import { generateModifyVars } from '../../generate/generateModifyVars';
|
||||
} from 'vite-plugin-theme'
|
||||
import { getThemeColors, generateColors } from '../../config/themeConfig'
|
||||
import { generateModifyVars } from '../../generate/generateModifyVars'
|
||||
|
||||
export function configThemePlugin(isBuild: boolean): PluginOption[] {
|
||||
const colors = generateColors({
|
||||
mixDarken,
|
||||
mixLighten,
|
||||
tinycolor,
|
||||
});
|
||||
})
|
||||
const plugin = [
|
||||
viteThemePlugin({
|
||||
resolveSelector: (s) => {
|
||||
s = s.trim();
|
||||
s = s.trim()
|
||||
switch (s) {
|
||||
case '.ant-steps-item-process .ant-steps-item-icon > .ant-steps-icon':
|
||||
return '.ant-steps-item-icon > .ant-steps-icon';
|
||||
return '.ant-steps-item-icon > .ant-steps-icon'
|
||||
case '.ant-radio-button-wrapper-checked:not(.ant-radio-button-wrapper-disabled)':
|
||||
case '.ant-radio-button-wrapper-checked:not(.ant-radio-button-wrapper-disabled):hover':
|
||||
case '.ant-radio-button-wrapper-checked:not(.ant-radio-button-wrapper-disabled):active':
|
||||
return s;
|
||||
return s
|
||||
case '.ant-steps-item-icon > .ant-steps-icon':
|
||||
return s;
|
||||
return s
|
||||
case '.ant-select-item-option-selected:not(.ant-select-item-option-disabled)':
|
||||
return s;
|
||||
return s
|
||||
default:
|
||||
if (s.indexOf('.ant-btn') >= -1) {
|
||||
// 按钮被重新定制过,需要过滤掉class防止覆盖
|
||||
return s;
|
||||
return s
|
||||
}
|
||||
}
|
||||
return s.startsWith('[data-theme') ? s : `[data-theme] ${s}`;
|
||||
return s.startsWith('[data-theme') ? s : `[data-theme] ${s}`
|
||||
},
|
||||
colorVariables: [...getThemeColors(), ...colors],
|
||||
}),
|
||||
@@ -83,7 +83,7 @@ export function configThemePlugin(isBuild: boolean): PluginOption[] {
|
||||
'alert-error-icon-color': '#a61d24',
|
||||
},
|
||||
}),
|
||||
];
|
||||
]
|
||||
|
||||
return plugin as unknown as PluginOption[];
|
||||
return plugin as unknown as PluginOption[]
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* Package file volume analysis
|
||||
*/
|
||||
import visualizer from 'rollup-plugin-visualizer';
|
||||
import { isReportMode } from '../../utils';
|
||||
import visualizer from 'rollup-plugin-visualizer'
|
||||
import { isReportMode } from '../../utils'
|
||||
|
||||
export function configVisualizerConfig() {
|
||||
if (isReportMode()) {
|
||||
@@ -11,7 +11,7 @@ export function configVisualizerConfig() {
|
||||
open: true,
|
||||
gzipSize: true,
|
||||
brotliSize: true,
|
||||
}) as Plugin;
|
||||
})
|
||||
}
|
||||
return [];
|
||||
return []
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
/**
|
||||
* Used to parse the .env.development proxy configuration
|
||||
*/
|
||||
import type { ProxyOptions } from 'vite';
|
||||
import type { ProxyOptions } from 'vite'
|
||||
|
||||
type ProxyItem = [string, string];
|
||||
type ProxyItem = [string, string]
|
||||
|
||||
type ProxyList = ProxyItem[];
|
||||
type ProxyList = ProxyItem[]
|
||||
|
||||
type ProxyTargetList = Record<string, ProxyOptions>;
|
||||
type ProxyTargetList = Record<string, ProxyOptions>
|
||||
|
||||
const httpsRE = /^https:\/\//;
|
||||
const httpsRE = /^https:\/\//
|
||||
|
||||
/**
|
||||
* Generate proxy
|
||||
* @param list
|
||||
*/
|
||||
export function createProxy(list: ProxyList = []) {
|
||||
const ret: ProxyTargetList = {};
|
||||
const ret: ProxyTargetList = {}
|
||||
for (const [prefix, target] of list) {
|
||||
const isHttps = httpsRE.test(target);
|
||||
const isHttps = httpsRE.test(target)
|
||||
|
||||
// https://github.com/http-party/node-http-proxy#options
|
||||
ret[prefix] = {
|
||||
@@ -28,7 +28,7 @@ export function createProxy(list: ProxyList = []) {
|
||||
rewrite: (path) => path.replace(new RegExp(`^${prefix}`), ''),
|
||||
// https is require secure=false
|
||||
...(isHttps ? { secure: false } : {}),
|
||||
};
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return ret
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
{
|
||||
"name": "vben-admin",
|
||||
"version": "2.8.0",
|
||||
"name": "paper-manager",
|
||||
"version": "0.0.1",
|
||||
"author": {
|
||||
"name": "vben",
|
||||
"email": "anncwb@126.com",
|
||||
"url": "https://github.com/anncwb"
|
||||
"name": "fumiama",
|
||||
"email": "fumiama@foxmail.com",
|
||||
"url": "https://github.com/fumiama"
|
||||
},
|
||||
"scripts": {
|
||||
"commit": "czg",
|
||||
"bootstrap": "pnpm install",
|
||||
"serve": "npm run dev",
|
||||
"serve": "pnpm run dev",
|
||||
"dev": "vite",
|
||||
"build": "cross-env NODE_ENV=production vite build && esno ./build/script/postBuild.ts",
|
||||
"build:test": "cross-env vite build --mode test && esno ./build/script/postBuild.ts",
|
||||
"build:no-cache": "pnpm clean:cache && npm run build",
|
||||
"report": "cross-env REPORT=true npm run build",
|
||||
"build:no-cache": "pnpm clean:cache && pnpm run build",
|
||||
"report": "cross-env REPORT=true pnpm run build",
|
||||
"type:check": "vue-tsc --noEmit --skipLibCheck",
|
||||
"preview": "npm run build && vite preview",
|
||||
"preview": "pnpm run build && vite preview",
|
||||
"preview:dist": "vite preview",
|
||||
"log": "conventional-changelog -p angular -i CHANGELOG.md -s",
|
||||
"clean:cache": "rimraf node_modules/.cache/ && rimraf node_modules/.vite",
|
||||
@@ -28,7 +28,7 @@
|
||||
"test:unit": "jest",
|
||||
"test:gzip": "npx http-server dist --cors --gzip -c-1",
|
||||
"test:br": "npx http-server dist --cors --brotli -c-1",
|
||||
"reinstall": "rimraf pnpm-lock.yaml && rimraf package.lock.json && rimraf node_modules && npm run bootstrap",
|
||||
"reinstall": "rimraf pnpm-lock.yaml && rimraf package.lock.json && rimraf node_modules && pnpm run bootstrap",
|
||||
"prepare": "husky install",
|
||||
"gen:icon": "esno ./build/generate/icon/index.ts"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user