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

Chore: tanstack-query, MSW, 절대 경로 설정 #10

Merged
merged 3 commits into from
Jul 23, 2024

Conversation

aquaman122
Copy link
Contributor

@aquaman122 aquaman122 commented Jul 23, 2024

💡 작업 내용

  • tanstack-query 세팅
  • 절대 경로 설정

💡 자세한 설명

🛠️ Tanstack-query 세팅

// provider/queryProvider 
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
import React, { useState } from 'react';

interface ReactQueryProviderProps {
  children: React.ReactNode;
  showDevTools?: boolean;
}

function ReactQueryProvider({
  showDevTools,
  children,
}: ReactQueryProviderProps) {
  const [client] = useState(
    new QueryClient({
      defaultOptions: {
        queries: {
          refetchOnWindowFocus: false,
          retryOnMount: true,
          refetchOnReconnect: false,
          retry: false,
        },
      },
    }),
  );
  return (
    <QueryClientProvider client={client}>
      {showDevTools && <ReactQueryDevtools buttonPosition="bottom-left" />}
      {children}
    </QueryClientProvider>
  );
}

ReactQueryProvider.defaultProps = {
  showDevTools: false,
};

export default ReactQueryProvider;
// main.tsx
import './index.css';
import React from 'react';
import { createRoot } from 'react-dom/client';
import { Provider } from 'react-redux';
import App from './App';
import { store } from './store';
import ReactQueryProvider from './provider/queryProvider';

createRoot(document.getElementById('root')!).render(
  <ReactQueryProvider showDevTools>
    <Provider store={store}>
      <App />
    </Provider>
  </ReactQueryProvider>,
);

🛠️ MSW 설정

// main.tsx
import './index.css';
import React from 'react';
import ReactDOM from 'react-dom/client';
import { Provider } from 'react-redux';
import App from './App';
import { store } from './store';
import ReactQueryProvider from './provider/queryProvider';

async function enableMocking(): Promise<void> {
  if (process.env.NODE_ENV !== 'development') {
    return;
  }

  const { worker } = await import('./mocks/browser');

  await worker.start();
}

enableMocking().then(() => {
  ReactDOM.createRoot(document.getElementById('root')!).render(
    <ReactQueryProvider showDevTools>
      <Provider store={store}>
        <App />
      </Provider>
    </ReactQueryProvider>,
  );
});
// mocks/browser.ts
import { setupWorker } from 'msw/browser';
import { handlers } from './handlers';

export const worker = setupWorker(...handlers);

export default worker;
// mocks/node.ts
import { setupServer } from 'msw/node';
import { handlers } from './handlers';

export const server = setupServer(...handlers);

export default server;

🛠️ 절대 경로 설정

// tsconfig.base.json
{
  "compilerOptions": {
    "target": "ES2020",
    "lib": ["DOM", "DOM.Iterable", "ES2020"],
    "module": "ESNext",
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "react-jsx",

    /* absolute paths */
    "baseUrl": "./src",
    "paths": {
      "@/*": ["/*"],
      "@/components/*": ["components/*"],
      "@/assets/*": ["assets/*"],
      "@/constants/*": ["constants/*"],
      "@/mocks/*": ["mocks/*"]
    }
  }
}



// vite.config.ts

/// <reference types="vitest" />

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { resolve } from 'path';

export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src'),
      '@/components': resolve(__dirname, 'src/components'),
      '@/assets': resolve(__dirname, 'src/assets'),
      '@/constants': resolve(__dirname, 'src/constants'),
      '@/mocks': resolve(__dirname, 'src/mocks'),
    },
  },
  test: {
    globals: true,
    environment: 'jsdom',
    setupFiles: './src/setupTests.ts',
  },
});




스크린샷 2024-07-23 오후 8 39 00



스크린샷 2024-07-23 오후 8 38 49

📗 참고 자료 (선택)

📢 리뷰 요구 사항 (선택)

🚩 후속 작업 (선택)

✅ 셀프 체크리스트

  • PR 제목을 형식에 맞게 작성했나요?
  • 브랜치 전략에 맞는 브랜치에 PR을 올리고 있나요? (master/main이 아닙니다.)
  • 이슈는 close 했나요?
  • Reviewers, Labels, Projects를 등록했나요?
  • 작업 도중 문서 수정이 필요한 경우 잘 수정했나요?
  • 테스트는 잘 통과했나요?
  • 불필요한 코드는 제거했나요?

closes #이슈번호

@aquaman122 aquaman122 added the ⚙️chore 세팅 관련 label Jul 23, 2024
@aquaman122 aquaman122 self-assigned this Jul 23, 2024
@aquaman122 aquaman122 changed the title Chore: tanstack-query 세팅 Chore: tanstack-query, 절대 경로 설정 Jul 23, 2024
@aquaman122 aquaman122 changed the title Chore: tanstack-query, 절대 경로 설정 Chore: tanstack-query, MSW, 절대 경로 설정 Jul 23, 2024
@aquaman122 aquaman122 changed the base branch from main to dev July 23, 2024 12:37
@aquaman122 aquaman122 merged commit 1e3c24c into dev Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚙️chore 세팅 관련
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant