'admin-20.12.21:处理打包字体图标404问题'

This commit is contained in:
lyt-Top 2020-12-21 00:14:57 +08:00
parent 873bb13242
commit 0fa35d56aa
4 changed files with 57 additions and 10 deletions

View File

@ -0,0 +1,2 @@
# public path
VITE_PUBLIC_PATH = 'vue-admin-wonderful-next-preview'

View File

@ -0,0 +1,2 @@
# public path
VITE_PUBLIC_PATH = ''

View File

@ -0,0 +1,31 @@
import dotenv from 'dotenv';
export interface ViteEnv {
VITE_PORT: number;
VITE_OPEN: boolean;
VITE_PUBLIC_PATH: string;
}
export function loadEnv(): ViteEnv {
const env = process.env.NODE_ENV;
const ret: any = {};
const envList = [`.env.${env}.local`, `.env.${env}`, '.env.local', '.env', ,]
envList.forEach((e) => {
dotenv.config({
path: e,
});
});
for (const envName of Object.keys(process.env)) {
let realName = (process.env as any)[envName].replace(/\\n/g, '\n');
realName = realName === 'true' ? true : realName === 'false' ? false : realName;
if (envName === 'VITE_PORT') {
realName = Number(realName);
}
if (envName === 'VITE_OPEN') {
realName = Boolean(realName);
}
ret[envName] = realName;
process.env[envName] = realName;
}
return ret;
}

View File

@ -1,15 +1,27 @@
import type { UserConfig } from 'vite';
import path from 'path';
import type { UserConfig } from 'vite'
import { resolve } from 'path'
import { loadEnv } from './build/utils'
const pathResolve = (dir: string): any => {
return resolve(__dirname, '.', dir)
}
const alias: Record<string, string> = {
'/@/': pathResolve('src'),
}
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_OPEN } = loadEnv()
const root: string = process.cwd()
const viteConfig: UserConfig = {
sourcemap: false,
base: '../',
port: 8080,
hostname: 'localhost',
open: false,
alias: {
'/@/': path.resolve(__dirname, './src')
},
root,
alias,
outDir: 'dist',
minify: 'esbuild',
port: VITE_PORT,
open: VITE_OPEN,
base: process.env.NODE_ENV === "production" ? "./" : VITE_PUBLIC_PATH,
}
export default viteConfig