Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#145] 배포시 env 적용 안되는 버그 해결 #147

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/src/apis/competitionList/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Competition } from './types';
export const fetchCompetitionList = async (): Promise<Competition[]> => {
try {
const response = await api.get('/competitions');

return response.data;
} catch (error) {
console.error('Error fetching competitions:', (error as Error).message);
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/utils/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import axios from 'axios';

console.log(333, import.meta.env.VITE_API_URL);

const api = axios.create({
baseURL: import.meta.env.VITE_API_URL,
});
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
// eslint-disable-next-line spaced-comment
/// <reference types="vite/client" />

export {};

declare global {
interface Window {
__API_URL__: string;
}
}
55 changes: 31 additions & 24 deletions frontend/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
import react from '@vitejs/plugin-react-swc';
import path from 'path';
import { defineConfig } from 'vite';
import { defineConfig, loadEnv } from 'vite';

export default defineConfig({
resolve: {
alias: [
{
find: '@',
replacement: path.resolve(__dirname, 'src'),
},
{
find: '@style',
replacement: path.resolve(__dirname, 'styled-system'),
},
],
},
build: {
rollupOptions: {
output: {
inlineDynamicImports: true,
export default () => {
const env = loadEnv('', process.cwd(), 'APP');
console.log(env, process.env, env.APP_API_URL);
return defineConfig({
resolve: {
alias: [
{
find: '@',
replacement: path.resolve(__dirname, 'src'),
},
{
find: '@style',
replacement: path.resolve(__dirname, 'styled-system'),
},
],
},
build: {
rollupOptions: {
output: {
inlineDynamicImports: true,
},
},
},
},
worker: {
format: 'es',
},
plugins: [react()],
});
worker: {
format: 'es',
},
plugins: [react()],
define: {
__API_URL__: JSON.stringify(env.APP_API_URL),
},
});
};