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

[FE] 개발환경과 빌드환경에 따라 msw 실행 여부를 결정하도록 msw 실행 조건문 개선 #212

Closed
wants to merge 4 commits into from
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
2 changes: 2 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dev": "webpack-dev-server --mode=development --open --hot --progress",
"start": "webpack serve --open --config webpack.config.js",
"build": "webpack --config webpack.config.js",
"serve": "http-server ./dist",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http-server를 사용하지 않고 webpack-dev-server를 활용하는 방법이 있는지 찾아보는 것도 좋을 것 같아요!

"lint:styles": "stylelint \"src/**/styles.ts\" --fix",
"test": "jest"
},
Expand Down Expand Up @@ -50,6 +51,7 @@
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.8",
"html-webpack-plugin": "^5.6.0",
"http-server": "^14.1.1",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-fixed-jsdom": "^0.0.2",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './page';
export * from './errorMessage';
export * from './review';
export * from './queryKeys';
export * from './system';
4 changes: 4 additions & 0 deletions frontend/src/constants/system.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const DEV_ENVIRONMENT = {
port: '3000',
hostname: 'localhost',
};
37 changes: 25 additions & 12 deletions frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { RecoilRoot } from 'recoil';

import App from '@/App';

import { DEV_ENVIRONMENT } from './constants';
import DetailedReviewPage from './pages/DetailedReviewPage';
import ErrorPage from './pages/ErrorPage';
import LandingPage from './pages/LandingPage';
Expand Down Expand Up @@ -60,15 +61,27 @@ const router = createBrowserRouter([

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);

root.render(
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<ThemeProvider theme={theme}>
<Global styles={globalStyles} />
<RecoilRoot>
<RouterProvider router={router} />
</RecoilRoot>
</ThemeProvider>
</QueryClientProvider>
</React.StrictMode>,
);
async function enableMocking() {
const { hostname, port } = DEV_ENVIRONMENT;
const isDev = window?.location.hostname === hostname && window.location.port === port;

if (isDev) {
const { worker } = await import('./mocks/browser');
return worker.start();
}
}

enableMocking().then(() => {
root.render(
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<ThemeProvider theme={theme}>
<Global styles={globalStyles} />
<RecoilRoot>
<RouterProvider router={router} />
</RecoilRoot>
</ThemeProvider>
</QueryClientProvider>
</React.StrictMode>,
);
});
Loading