하나의 코드로 웹(Web) + 모바일(App) 두 플랫폼에서 사용 가능하도록 만든다.
React-Native를 중심으로 해서 UI를 제작하고 그걸 웹에서는 Next.js + 모바일에서는 React-Native가 렌더링하는 구조로 만들려고 함
여러 프로젝트를 한 저장소에서 함께 관리하도록 하는 방식임
# Global install
yarn global add turbo
# Install in repository
yarn add turbo --dev
{
"$schema": "https://turbo.build/schema.json",
"tasks": {
"build": {
"dependsOn": ["^build"],
"outputs": [".next/**", "!.next/cache/**"]
},
"check-types": {
"dependsOn": ["^check-types"]
},
"dev": {
"persistent": true,
"cache": false
}
}
}
아래와 같은 구조로 프로젝트 구성하였다.
CheckBiz/
|----- apps/
| |----- web/
| |----- mobile/
|----- packages/
| |----- ui/
| |----- lib/
cd apps
yarn create next-app web --typescript
yarn add react-native react-native-web
4.next.config.ts 작성
공식문서
resolve: {
alias: {
'react-native$': 'react-native-web'
}
}
로서 next.config.ts 에서 react-native를 react-native-web으로 alias를 설정하는 것은 공식적인 설정 방식임
나의 경우
// apps/web/next.config.ts
import type { NextConfig } from 'next'
const nextConfig: NextConfig = {
webpack: (config) => {
config.resolve.alias = {
...(config.resolve.alias || {}),
'react-native$': 'react-native-web',
};
config.resolve.extensions = [
'.web.ts',
'.web.tsx',
'.ts',
'.tsx',
'.js',
'.jsx',
'.json',
];
return config;
}
};
export default nextConfig;
이렇게 작성했음!