ããã³ãã¨ã³ãã®ã¢ãã¬ãæ§æã¯ã¹ã±ã¼ãªã³ã°ã®å¤¢ãè¦ãã
Published on
ããã£ã½ãã¿ã¤ãã«ãä»ãã¾ãããç¹ã«æå³ã¯ãªãã§ãã
workspace ã使ã£ãã³ãã³ããæé©åãã¦å®è¡ãã Turborepo ã«ã¤ãã¦ã®ã話㧠Turborepo ã軽ã触ã£ã¦ã¿ãéã«npx create-turbo@latest
ã§ä½ãããæ§æãã¨ã¦ãããããããããããã¯ãã®åæ段éããã¢ãã¬ããæ¡ç¨ããã®ã¯é¸æè¢ã® 1 ã¤ã¨ãã¦ããã®ã§ã¯ãã¨æãç¶ç·¨ãæ¸ãã¾ããã
ååã¨åãããµã³ãã«ã®ãªãã¸ããªã¯ãã¡ãã«ãªãã¾ãã
https://github.com/nus3/p-turborepo/tree/main/yarn
æ¦è¦
- ã¢ãã¬ããæ¡ç¨ãããã¨ã§ãåä¸ãªãã¸ããªå ã§èªä½ããæ±ç¨çãªã©ã¤ãã©ãªãã³ã³ãã¼ãã³ããè¤æ°ã®ã¢ããªã±ã¼ã·ã§ã³ã§ä½¿ãã¾ããã
- ã¢ãã¬ãã®è¦æ¨¡ã大ãããªã£ã¦ããå ´åã«ã¯ãã¢ãã¬ãå ã®ããã±ã¼ã¸ã npm ã«å ¬éãããã¨ã§ã¢ããªã±ã¼ã·ã§ã³ã¨ããã±ã¼ã¸ãéåæã«éçºã§ãã
- Yarn ã npm ã® workspace ã¯ã¤ã¤ã¾ï¼
ã¢ãã¬ãã¨ã¯
ã¢ãã¬ãã¨ã¯æ¬è¨äºã§ã¯ npm ã Yarn ã® workspaces æ©è½ã使ãã1 ã¤ã®ãªãã¸ããªå ã§è¤æ°ã® npm ããã±ã¼ã¸ã管çãã¦ããæ§æã®ãã¨ã¨ãã¾ãã
npm ã Yarn ã® workspaces
npm ã Yarn ã® workspaces 㯠1 ã¤ã®ãªãã¸ããªå ã§è¤æ°ã® npm ããã±ã¼ã¸ã管çããããã®æ©è½ã§ãã
workspaces ã使ãã«ã¯ãªãã¸ããªã®ã«ã¼ãç´ä¸ã«ããpackage.json
ã«workspaces
ã追å ãã¾ãã
ä¾ãã°apps
é
ä¸ã«ã¢ããªã±ã¼ã·ã§ã³ã® npm ããã±ã¼ã¸ããpackages
é
ä¸ã«æ±ç¨çãªã³ã³ãã¼ãã³ããã©ã¤ãã©ãªãªã©ã® npm ããã±ã¼ã¸ãå
¥ããå ´åã次ã®ããã«ãªãã¾ãã
{
"workspaces": ["apps/*", "packages/*"]
}
apps
é
ä¸ã«ããnus3-a
ã¨ããã¢ããªã±ã¼ã·ã§ã³ãã packages
é
ä¸ã«ããnus3-ui
ã¨ããååã® npm ããã±ã¼ã¸ã使ãå ´åããããã次ã®ãããªpackage.json
ã«ãªãã¾ãã
apps/nus3-a
{
"name": "nus3-a",
"version": "0.0.0",
"dependencies": {
"nus3-ui": "*"
// Yarnã®v2以éã§ããã°`workspace:`æ§æã使ããããã«ãªã
// REF: (nus3) https://yarnpkg.com/features/workspaces#workspace-ranges-workspace
// "nus3-ui": "workspace:*"
}
}
packages/nus3-ui
{
"name": "nus3-ui",
"version": "0.0.0"
}
workspaces å ã«ãã npm ããã±ã¼ã¸ã®ååã npm ã«å ¬éããã¦ããããã±ã¼ã¸åã¨åãå ´åã¯ã workspace å ã® npm ããã±ã¼ã¸ãåªå ãã¦ã¤ã³ã¹ãã¼ã«ããã¾ããå¾ã workspaces å ã® npm ããã±ã¼ã¸ãå ¬éããå¯è½æ§ãããå ´åãããã±ã¼ã¸å㯠npm ã§å ¬éããã¦ããããã±ã¼ã¸åã¨è¢«ããªãååã«ããæ¹ãè¯ãããããã¾ããã
workspace å
ã® npm ããã±ã¼ã¸ãä¾åé¢ä¿ã«è¿½å ãã㨠node_modules ã«ã·ã³ããªãã¯ãªã³ã¯ãä½æããã¾ãã次ã®ç»åã®ããã« node_modules é
ä¸ã«nus3-ui
ã¨nus3-a
ã®ã·ã³ããªãã¯ãªã³ã¯ã追å ããã¦ãããã¨ã確èªã§ãã¾ãã
ã·ã³ããªãã¯ãªã³ã¯ã«ããä¾åãã npm ããã±ã¼ã¸ã®ã³ã¼ããç´æ¥åç
§ããã®ã§ãnpm ã«å
¬éããã¼ã¸ã§ã³ç®¡çããã¾ã§ã¯ãversion ã¯0.0.0
ããã¤ã使ãå´ã¯"nus3-ui": "*"
ã®ããã«ã¯ã¤ã«ãã«ã¼ããæå®ããã¨ãã¼ã¸ã§ã³ã®ãã¨ãæèããã«ç®¡çã§ãã¾ãã
create-turbo ã§ä½ãããã¢ãã¬ãæ§æ
create-turbo(npx create-turbo@latest
) ã§ã¯ä½ãããã¢ãã¬ãæ§æã«æ¬¡ã®ãããªãã®ãå«ã¾ãã¾ãã
- npm ã«å ¬éããã« config ãã¢ãã¬ãå ã®å¥ããã±ã¼ã¸ã«åãã¦ãè¤æ°ã®ããã±ã¼ã¸ãã使ç¨ãã
- React ã使ã£ãæ±ç¨çãªã³ã³ãã¼ãã³ã(tsx)ãå¥ããã±ã¼ã¸ã«åã㦠ã¢ããªã±ã¼ã·ã§ã³(Next.js)ã§ä½¿ç¨ãã
ããããè¦ã¦ããã¾ãããã
npm ã«å ¬éããã« config ãã¢ãã¬ãå ã®å¥ããã±ã¼ã¸ã«åãã¦ãè¤æ°ã®ããã±ã¼ã¸ãã使ç¨ãã
ESLint ã Stylelint ã® config 㯠npm ã«å ¬éãããã¨ã§ãç°ãªãããã¸ã§ã¯ãã§å ±éã®è¨å®ã使ãã¾ãããµã¤ãã¦ãºã§ã¯@cybozu/eslint-configã@cybozu/stylelint-configã¨ã㦠npm ã«å ¬éãã¦ãã¾ãã
ã¢ãã¬ãå ã§ããã° ESLint ã Stylelint ã®è¨å®ã npm ã«å ¬éã»ç®¡çããã«å ±æãããã¨ãã§ãã¾ãã
packages/nus3-config
ã§å
±éã® ESLint ã TSConfig ãå®ç¾©ãã¦ãpackage.json
ã®files
ã«æå®ãã¾ãã
{
"name": "nus3-config",
"version": "0.0.0",
"files": [
"eslint-preset.js",
"tsconfig.base.json",
"tsconfig.nextjs.json",
"tsconfig.react-library.json"
]
}
apps/nus3-a
ã§nus3-config
ã追å ããnus3-config
ãã TSConfig ã ESLint ã®ã«ã¼ã«ãé©ç¨ãã¾ãã
{
"name": "nus3-a",
"version": "0.0.0",
"devDependencies": {
"eslint": "8.6.0",
"nus3-config": "*"
}
}
apps/nus3-a/tsconfig.json
{
"extends": "nus3-config/tsconfig.nextjs.json"
}
apps/nus3-a/.eslintrc
module.exports = require("nus3-config/eslint-preset");
React ã使ã£ãæ±ç¨çãªã³ã³ãã¼ãã³ã(tsx)ãå¥ããã±ã¼ã¸ã«åã㦠ã¢ããªã±ã¼ã·ã§ã³(Next.js)ã§ä½¿ç¨ãã
create-turbo ã§ã¯æ±ç¨ç㪠React ã³ã³ãã¼ãã³ãã tsx ãã¡ã¤ã«ã®ã¾ã¾ packages
é
ä¸ã® npm ããã±ã¼ã¸ã§ç®¡çããNext.js ã®pluginã使ã£ã¦ ã¢ããªã±ã¼ã·ã§ã³ å´ã§ãã©ã³ã¹ãã¤ã«ãã¦ãã¾ãã
packages/nus3-ui
㧠React(tsx)ã®ã³ã³ãã¼ãã³ããå®è£
ãã¾ããå®è£
ãã tsx ãã¡ã¤ã«ã®ãã¹ããã®ã¾ã¾main
ã¨types
ã«è¿½å ãã¾ãã
{
"name": "nus3-ui",
"version": "0.0.0",
"main": "./index.tsx",
"types": "./index.tsx",
"devDependencies": {
"@types/react": "17.0.37",
"@types/react-dom": "17.0.11",
"typescript": "4.5.4"
}
}
packages/nus3-ui/index.tsx
import { VFC } from "react";
export const Button: VFC = () => {
return <button>ãã¿ã³</button>;
};
apps/nus3-a
nus3-ui
ã® tsx ãã¡ã¤ã«ãnus3-a
ã§next-transpile-modules
ã使ã£ã¦ãã©ã³ã¹ãã¤ã«ãã¾ãã
{
"name": "nus3-a",
"version": "0.0.0",
"devDependencies": {
"next-transpile-modules": "9.0.0"
}
}
apps/nus3-a/next.config.js
const withTM = require("next-transpile-modules")(["nus3-ui"]);
module.exports = withTM({});
ããã³ãã¨ã³ãã®ã¢ãã¬ãæ¦ç¥
çè ã®ããã¾ã§ã®çµé¨ã§ã¯ãåµæ¥ãã¦éããªãä¼ç¤¾ããããã¯ãã®åæãã§ã¼ãºã§ãè¤æ°ã®ã¢ããªã±ã¼ã·ã§ã³ã®éçºã並åãã¦å§ã¾ããã¨ãå¤ãããã¾ããããããã£ãç¶æ³ã§ã¯ãã¢ãã¬ããæ¡ç¨ãã¦ããã¨è¤æ°ã®ã¢ããªã±ã¼ã·ã§ã³ã§å ±éããã³ã³ãã¼ãã³ããã©ã¤ãã©ãªãå°ãªãã³ã¹ãã§ä½¿ç¨ã§ãã¾ãã
ã¾ããã¢ãã¬ãå ã§å ±éãã¦ä½¿ã£ã¦ããããã±ã¼ã¸ã«å¤æ´ãå ããéã«ããã®å½±é¿ç¯å²ãææ¡ã§ããªããããã¢ãã¬ãã®è¦æ¨¡ã大ãããªã£ãå ´åã«ã¯ãããã±ã¼ã¸ã npm ã«å ¬éãã¦ãã¼ã¸ã§ã³ç®¡çãããã¨ã§ããã¼ã¸ã§ã³ã®å¤æ´ã¿ã¤ãã³ã°ãåã ã®ã¢ããªã±ã¼ã·ã§ã³ã«ä»»ãããã¨ãã§ããã¢ããªã±ã¼ã·ã§ã³ã¨ããã±ã¼ã¸ã®éçºãéåæã«è¡ããã¨ãã§ãã¾ãã
ãã®ããã«ãåæ段éã§ã¯æ±ç¨ç㪠npm ããã±ã¼ã¸ãã¢ã»ããã¨ãã¦è¤æ°ã®ã¢ããªã±ã¼ã·ã§ã³ã«æä¾ãããã¨ã§éçºã¹ãã¼ããä¸ããããã¾ããè¦æ¨¡ã大ãããªã£ã¦ããå ´åã¯ããã±ã¼ã¸ã npm ã«å ¬éããã¨ãã£ãæ¹éãã¨ããã¨ãã§ãã¾ãã
ãã¡ããã1 ã¤ã®ãªãã¸ããªã§ãã¹ã¦ã®ããã±ã¼ã¸ã管çãããã¨ãã³ã¼ããã¼ã¹ã大ããè¤éã«ãªããã¨ãªã©ãã¡ãªããããããã¢ãã¬ããæ¡ç¨ãããã¨ãé©åã§ã¯ãªãå ´åãããã¾ããã¡ãªããã»ãã¡ãªãããè¸ã¾ãã¤ã¤ãããã³ãã¨ã³ãã®æè¡é¸å®ã®ä¸ã«ã¢ãã¬ãã®æ¡ç¨ãé¸æè¢ã® 1 ã¤ã¨ãã¦å ¥ãã¦ãããããããã¾ããã
è¨äºã«é¢ããå ±åãªã©ã¯ãã¡ããã