feat(GOV-009): 建立 Vue 前端工程基线
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
import vue from '@vitejs/plugin-vue';
|
||||
import { parse } from 'dotenv';
|
||||
import { defineConfig } from 'vite';
|
||||
|
||||
const webDirectory = path.dirname(fileURLToPath(import.meta.url));
|
||||
const developmentEnvFile = path.resolve(webDirectory, '../deploy/env/development/web.env.local');
|
||||
|
||||
function readDevelopmentPublicEnv() {
|
||||
if (process.env.NODE_ENV === 'production') return {};
|
||||
try {
|
||||
return Object.fromEntries(
|
||||
Object.entries(parse(readFileSync(developmentEnvFile))).filter(([key]) =>
|
||||
key.startsWith('VITE_'),
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code === 'ENOENT') return {};
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
const publicEnv = readDevelopmentPublicEnv();
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
define: Object.fromEntries(
|
||||
Object.entries(publicEnv).map(([key, value]) => [
|
||||
`import.meta.env.${key}`,
|
||||
JSON.stringify(value),
|
||||
]),
|
||||
),
|
||||
server: {
|
||||
host: '127.0.0.1',
|
||||
port: 5173,
|
||||
strictPort: true,
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user