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