💡 작업중! - Github
root
│
├── packages
├── APP (React Native App)
├── CRA (Create React App)
├── VITE (Vite Project)
└── COMMON (공통 코드)
private: true
workspaces
<string[]>
// workspace 루트 경로 package.json
// pakcages내 디렉토리 내부 모든 프로젝트
...
"workspaces": {
"packages": [
"packages/*"
]
}
nohoist
<string[]>
"workspaces": {
...
"nohoist": [
"**/@react-native-async-storage/async-storage",
"**/react",
"**/react-dom",
"**/react-native",
"**/react-native/**",
"**/react-native-codegen",
"**/react-native-dev-menu",
"**/react-native-macos",
"**/react-native-windows",
"jetifier",
"react-native-safe-area-context",
"react-native-screens",
"@react-native-community/**",
"@react-navigation/**",
"metro",
"react-query"
]
},
script
"scripts": {
"reset": "find . -type dir -name node_modules | xargs rm -rf && rm -rf yarn.lock",
"cra:start": "yarn workspace cra start",
"vite:start": "yarn workspace vite dev",
"app:android": "yarn workspace app android",
"app:ios": "yarn workspace app ios"
},
cra 프로젝트에서 common 패키지 코드 사용시 에러
이유
const path = require("path");
const { getLoader, loaderByName } = require("@craco/craco");
//COMMON 패키지 추가
const packages = [];
packages.push(path.join(__dirname, "../COMMON"));
module.exports = {
webpack: {
configure: (webpackConfig, arg) => {
const { isFound, match } = getLoader(webpackConfig, loaderByName("babel-loader"));
if (isFound) {
const include = Array.isArray(match.loader.include) ? match.loader.include : [match.loader.include];
match.loader.include = include.concat(packages);
}
return webpackConfig;
},
},
};
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test --watchAll --detectOpenHandles",
"eject": "craco eject"
},
// metro.config.js
module.exports = {
...
watchFolders: ['../../node_modules', '../common'],
...
};
// metro.config.js
const {getMetroTools} = require('react-native-monorepo-tools');
const monorepoMetroTools = getMetroTools();
module.exports = {
...
watchFolders: monorepoMetroTools.watchFolders,
...
};
// react-native-monorepo-tools/src/get-metro.tools/js
const monorepoRoot = getMonorepoRoot({ cwd });
const watchFolders = [
// monorepo 루트 경로의 node_modules 디렉토리 감시
path.join(monorepoRoot, "/node_modules"),
// workspaces의 packages 하위 디렉토리 감시
...getWorkspaces({ cwd }),
];