[{"data":1,"prerenderedAt":1003},["ShallowReactive",2],{"series-\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fgetting-started-with-monorepo-linter-and-formatter":3,"series-context-\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library":778},{"id":4,"title":5,"body":6,"contentId":765,"date":766,"description":767,"extension":768,"github":769,"meetTheInstructor":769,"meta":770,"navigation":453,"part":84,"path":771,"rawbody":772,"robots":769,"schemaOrg":769,"seo":773,"seriesSlug":774,"sitemap":775,"stem":776,"subtitle":769,"topics":769,"__hash__":777},"series\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fgetting-started-with-monorepo-linter-and-formatter.md","Getting Started with Monorepo, Linter, and Formatter",{"type":7,"value":8,"toc":760},"minimark",[9,26,34,39,54,67,70,114,121,191,210,219,225,245,252,262,266,274,284,303,322,325,352,357,362,410,428,500,503,518,521,535,539,547,550,623,637,664,671,688,694,717,720,726,729,741,744,753,756],[10,11,12,13,17,18,21,22,25],"p",{},"In this series, we will begin from scratch. This is the optimal way to comprehend the process. We'll establish a ",[14,15,16],"strong",{},"monorepo"," and set up a ",[14,19,20],{},"linter"," and a ",[14,23,24],{},"formatter",".",[27,28,31],"callout",{"color":29,"icon":30},"info","i-ph-info-duotone",[10,32,33],{},"The process is versatile and can be applied to any project, not just a component library.",[35,36,38],"h2",{"id":37},"setting-up-the-project","Setting up the project",[10,40,41,42,44,45,49,50,53],{},"A ",[14,43,16],{}," is a repository housing multiple projects. In our case, we will have the package ",[46,47,48],"code",{},"@barbapapazes\u002Fhuchet-vue",", two playgrounds, and a storybook. Employing a monorepo enables the management of all these projects within a single repository, facilitates code sharing, and allows for a single dependency installation, keeping everything synchronized and compatible. We could easily imagine adding more packages in the future, such as a custom ",[14,51,52],{},"Tailwind CSS"," configuration or a shared utility library.",[10,55,56,57,66],{},"To create a monorepo, we'll utilize ",[58,59,63],"a",{"href":60,"rel":61},"https:\u002F\u002Fpnpm.io\u002Fworkspaces",[62],"nofollow",[14,64,65],{},"pnpm workspaces",", a feature within the pnpm package manager that installs dependencies smartly, using hard links and symlinks to save disk space and time.",[10,68,69],{},"First, create a new directory and initialize a new git repository:",[71,72,78],"pre",{"className":73,"code":74,"filename":75,"language":76,"meta":77,"style":77},"language-bash shiki shiki-themes github-light github-light github-dark","mkdir huchet-vue && cd huchet-vue && npm init -y\n","terminal","bash","",[46,79,80],{"__ignoreMap":77},[81,82,85,89,93,97,101,103,105,108,111],"span",{"class":83,"line":84},"line",1,[81,86,88],{"class":87},"snPdu","mkdir",[81,90,92],{"class":91},"sIIMD"," huchet-vue",[81,94,96],{"class":95},"sxrX7"," && ",[81,98,100],{"class":99},"sBjJW","cd",[81,102,92],{"class":91},[81,104,96],{"class":95},[81,106,107],{"class":87},"npm",[81,109,110],{"class":91}," init",[81,112,113],{"class":99}," -y\n",[10,115,116,117,120],{},"Open this folder in your code editor and modify the ",[46,118,119],{},"package.json"," file:",[71,122,126],{"className":123,"code":124,"filename":119,"language":125,"meta":77,"style":77},"language-json shiki shiki-themes github-light github-light github-dark","{\n  \"name\": \"huchet-vue\",\n  \"version\": \"0.0.0\",\n  \"type\": \"module\",\n  \"private\": true\n}\n","json",[46,127,128,133,148,161,174,185],{"__ignoreMap":77},[81,129,130],{"class":83,"line":84},[81,131,132],{"class":95},"{\n",[81,134,136,139,142,145],{"class":83,"line":135},2,[81,137,138],{"class":99},"  \"name\"",[81,140,141],{"class":95},": ",[81,143,144],{"class":91},"\"huchet-vue\"",[81,146,147],{"class":95},",\n",[81,149,151,154,156,159],{"class":83,"line":150},3,[81,152,153],{"class":99},"  \"version\"",[81,155,141],{"class":95},[81,157,158],{"class":91},"\"0.0.0\"",[81,160,147],{"class":95},[81,162,164,167,169,172],{"class":83,"line":163},4,[81,165,166],{"class":99},"  \"type\"",[81,168,141],{"class":95},[81,170,171],{"class":91},"\"module\"",[81,173,147],{"class":95},[81,175,177,180,182],{"class":83,"line":176},5,[81,178,179],{"class":99},"  \"private\"",[81,181,141],{"class":95},[81,183,184],{"class":99},"true\n",[81,186,188],{"class":83,"line":187},6,[81,189,190],{"class":95},"}\n",[27,192,193],{"color":29,"icon":30},[10,194,195,196,199,200,203,204,206,207,209],{},"Setting the ",[46,197,198],{},"private"," field to ",[46,201,202],{},"true"," in a ",[46,205,119],{}," file prevents accidental publication to the npm registry. Our root ",[46,208,119],{}," is for monorepo management rather than publication.",[10,211,212,213,215,216,218],{},"This ",[46,214,119],{}," is the primary file for our monorepo. Future packages will each have their own ",[46,217,119],{},". The main file will only include dependencies and scripts impacting the entire monorepo, not shared between packages.",[10,220,221,222,120],{},"Before proceeding, adjust a pnpm setting by creating a ",[46,223,224],{},".npmrc",[71,226,228],{"className":73,"code":227,"filename":119,"language":76,"meta":77,"style":77},"echo \"shamefully-hoist=true\" > .npmrc\n",[46,229,230],{"__ignoreMap":77},[81,231,232,235,238,242],{"class":83,"line":84},[81,233,234],{"class":99},"echo",[81,236,237],{"class":91}," \"shamefully-hoist=true\"",[81,239,241],{"class":240},"s8jYJ"," >",[81,243,244],{"class":91}," .npmrc\n",[10,246,247,248,251],{},"This setting allows pnpm to hoist dependencies to the root ",[46,249,250],{},"node_modules"," folder. While not default or recommended, it is necessary in our case.",[27,253,254],{"color":29,"icon":30},[10,255,256,257,259,260,25],{},"By default, pnpm creates a semistrict ",[46,258,250],{},", allowing access to undeclared dependencies only from within ",[46,261,250],{},[35,263,265],{"id":264},"linter-and-formatter","Linter and formatter",[10,267,268,269,21,271,273],{},"Adding a ",[14,270,20],{},[14,272,24],{}," ensures our code remains clean and consistent, a fundamental requirement for any project, especially a component library used by other developers.",[27,275,276],{"color":29,"icon":30},[10,277,41,278,280,281,283],{},[14,279,24],{}," automatically formats your code according to set rules, while a ",[14,282,20],{}," analyzes code statically to detect potential errors and enforce rules.",[10,285,286,287,294,295,302],{},"Commonly, ",[58,288,291],{"href":289,"rel":290},"https:\u002F\u002Fprettier.io\u002F",[62],[14,292,293],{},"Prettier"," is used as a formatter, and ",[58,296,299],{"href":297,"rel":298},"https:\u002F\u002Feslint.org\u002F",[62],[14,300,301],{},"ESLint"," as a linter. Both have extensive plugins and configurations, but integrating them can be complex. As I'm not opinionated about code style, less configuration is better.",[10,304,305,306,311,312,314,315,25],{},"For this project, as with all my projects, we'll use the ESLint configuration by ",[58,307,310],{"href":308,"rel":309},"https:\u002F\u002Fantfu.me\u002F",[62],"Anthony Fu",". It's a highly opinionated setup using ",[14,313,301],{}," and ",[58,316,319],{"href":317,"rel":318},"https:\u002F\u002Feslint.style\u002F",[62],[14,320,321],{},"Stylistic",[10,323,324],{},"Install it with a simple command:",[71,326,328],{"className":73,"code":327,"filename":75,"language":76,"meta":77,"style":77},"npx @antfu\u002Feslint-config@latest && pnpm add -D typescript\n",[46,329,330],{"__ignoreMap":77},[81,331,332,335,338,340,343,346,349],{"class":83,"line":84},[81,333,334],{"class":87},"npx",[81,336,337],{"class":91}," @antfu\u002Feslint-config@latest",[81,339,96],{"class":95},[81,341,342],{"class":87},"pnpm",[81,344,345],{"class":91}," add",[81,347,348],{"class":99}," -D",[81,350,351],{"class":91}," typescript\n",[27,353,354],{"color":29,"icon":30},[10,355,356],{},"These are installed at the root of the monorepo to maintain a unified source of truth for linting and formatting, a common monorepo practice.",[10,358,359,360,120],{},"Add two scripts to your ",[46,361,119],{},[71,363,365],{"className":123,"code":364,"filename":119,"language":125,"meta":77,"style":77},"{\n  \"scripts\": {\n    \"lint\": \"eslint .\",\n    \"lint:fix\": \"eslint --fix .\"\n  }\n}\n",[46,366,367,371,379,391,401,406],{"__ignoreMap":77},[81,368,369],{"class":83,"line":84},[81,370,132],{"class":95},[81,372,373,376],{"class":83,"line":135},[81,374,375],{"class":99},"  \"scripts\"",[81,377,378],{"class":95},": {\n",[81,380,381,384,386,389],{"class":83,"line":150},[81,382,383],{"class":99},"    \"lint\"",[81,385,141],{"class":95},[81,387,388],{"class":91},"\"eslint .\"",[81,390,147],{"class":95},[81,392,393,396,398],{"class":83,"line":163},[81,394,395],{"class":99},"    \"lint:fix\"",[81,397,141],{"class":95},[81,399,400],{"class":91},"\"eslint --fix .\"\n",[81,402,403],{"class":83,"line":176},[81,404,405],{"class":95},"  }\n",[81,407,408],{"class":83,"line":187},[81,409,190],{"class":95},[10,411,412,413,416,417,420,421,424,425,427],{},"Update the ",[46,414,415],{},"eslint.config.ts"," file to support ",[14,418,419],{},"Vue",", ",[14,422,423],{},"TypeScript",", and ",[14,426,321],{},":",[71,429,433],{"className":430,"code":431,"filename":415,"language":432,"meta":77,"style":77},"language-typescript shiki shiki-themes github-light github-light github-dark","import antfu from '@antfu\u002Feslint-config'\n\nexport default antfu({\n  stylistic: true,\n  vue: true,\n  typescript: true\n})\n","typescript",[46,434,435,449,455,469,478,487,494],{"__ignoreMap":77},[81,436,437,440,443,446],{"class":83,"line":84},[81,438,439],{"class":240},"import",[81,441,442],{"class":95}," antfu ",[81,444,445],{"class":240},"from",[81,447,448],{"class":91}," '@antfu\u002Feslint-config'\n",[81,450,451],{"class":83,"line":135},[81,452,454],{"emptyLinePlaceholder":453},true,"\n",[81,456,457,460,463,466],{"class":83,"line":150},[81,458,459],{"class":240},"export",[81,461,462],{"class":240}," default",[81,464,465],{"class":87}," antfu",[81,467,468],{"class":95},"({\n",[81,470,471,474,476],{"class":83,"line":163},[81,472,473],{"class":95},"  stylistic: ",[81,475,202],{"class":99},[81,477,147],{"class":95},[81,479,480,483,485],{"class":83,"line":176},[81,481,482],{"class":95},"  vue: ",[81,484,202],{"class":99},[81,486,147],{"class":95},[81,488,489,492],{"class":83,"line":187},[81,490,491],{"class":95},"  typescript: ",[81,493,184],{"class":99},[81,495,497],{"class":83,"line":496},7,[81,498,499],{"class":95},"})\n",[10,501,502],{},"Now, you can lint your code:",[71,504,506],{"className":73,"code":505,"filename":75,"language":76,"meta":77,"style":77},"pnpm run lint\n",[46,507,508],{"__ignoreMap":77},[81,509,510,512,515],{"class":83,"line":84},[81,511,342],{"class":87},[81,513,514],{"class":91}," run",[81,516,517],{"class":91}," lint\n",[10,519,520],{},"And automatically fix issues:",[71,522,524],{"className":73,"code":523,"filename":75,"language":76,"meta":77,"style":77},"pnpm run lint:fix\n",[46,525,526],{"__ignoreMap":77},[81,527,528,530,532],{"class":83,"line":84},[81,529,342],{"class":87},[81,531,514],{"class":91},[81,533,534],{"class":91}," lint:fix\n",[35,536,538],{"id":537},"defining-our-monorepo","Defining our monorepo",[10,540,541,542,314,544,546],{},"With the ",[14,543,20],{},[14,545,24],{}," set up, we can start defining our monorepo.",[10,548,549],{},"We will have the following structure:",[71,551,556],{"className":552,"code":553,"filename":554,"language":555,"meta":77,"style":77},"language-txt shiki shiki-themes github-light github-light github-dark",".\n├── .histoire\n│   └── package.json\n├── package.json\n├── packages\n│   └── huchet-vue\n│       └── package.json\n└── playground\n    ├── nuxt\n    │   └── package.json\n    └── vue\n        └── package.json\n","Example","txt",[46,557,558,563,568,573,578,583,588,593,599,605,611,617],{"__ignoreMap":77},[81,559,560],{"class":83,"line":84},[81,561,562],{},".\n",[81,564,565],{"class":83,"line":135},[81,566,567],{},"├── .histoire\n",[81,569,570],{"class":83,"line":150},[81,571,572],{},"│   └── package.json\n",[81,574,575],{"class":83,"line":163},[81,576,577],{},"├── package.json\n",[81,579,580],{"class":83,"line":176},[81,581,582],{},"├── packages\n",[81,584,585],{"class":83,"line":187},[81,586,587],{},"│   └── huchet-vue\n",[81,589,590],{"class":83,"line":496},[81,591,592],{},"│       └── package.json\n",[81,594,596],{"class":83,"line":595},8,[81,597,598],{},"└── playground\n",[81,600,602],{"class":83,"line":601},9,[81,603,604],{},"    ├── nuxt\n",[81,606,608],{"class":83,"line":607},10,[81,609,610],{},"    │   └── package.json\n",[81,612,614],{"class":83,"line":613},11,[81,615,616],{},"    └── vue\n",[81,618,620],{"class":83,"line":619},12,[81,621,622],{},"        └── package.json\n",[10,624,625,626,629,630,633,634,636],{},"For now, create the ",[46,627,628],{},"packages"," folder and the ",[46,631,632],{},"huchet-vue"," package with its ",[46,635,119],{}," file. Additional packages will be developed in future parts of this series.",[71,638,640],{"className":73,"code":639,"filename":119,"language":76,"meta":77,"style":77},"mkdir -p packages\u002Fhuchet-vue\necho '{\\n\"name\": \"@barbapapazes\u002Fhuchet-vue\",\\n\"type\": \"module\",\\n\"version\": \"0.0.0\"\\n}' > packages\u002Fhuchet-vue\u002Fpackage.json\n",[46,641,642,652],{"__ignoreMap":77},[81,643,644,646,649],{"class":83,"line":84},[81,645,88],{"class":87},[81,647,648],{"class":99}," -p",[81,650,651],{"class":91}," packages\u002Fhuchet-vue\n",[81,653,654,656,659,661],{"class":83,"line":135},[81,655,234],{"class":99},[81,657,658],{"class":91}," '{\\n\"name\": \"@barbapapazes\u002Fhuchet-vue\",\\n\"type\": \"module\",\\n\"version\": \"0.0.0\"\\n}'",[81,660,241],{"class":240},[81,662,663],{"class":91}," packages\u002Fhuchet-vue\u002Fpackage.json\n",[10,665,666,667,670],{},"Having two packages allows us to define them in a ",[46,668,669],{},"pnpm-workspace.yaml"," file at the root of our monorepo:",[71,672,674],{"className":73,"code":673,"filename":669,"language":76,"meta":77,"style":77},"echo 'packages:\\n  - packages\u002F*' > pnpm-workspace.yaml\n",[46,675,676],{"__ignoreMap":77},[81,677,678,680,683,685],{"class":83,"line":84},[81,679,234],{"class":99},[81,681,682],{"class":91}," 'packages:\\n  - packages\u002F*'",[81,684,241],{"class":240},[81,686,687],{"class":91}," pnpm-workspace.yaml\n",[10,689,690,691,693],{},"Ensure ",[46,692,669],{}," file looks like:",[71,695,699],{"className":696,"code":697,"filename":669,"language":698,"meta":77,"style":77},"language-yaml shiki shiki-themes github-light github-light github-dark","packages:\n  - packages\u002F*\n","yaml",[46,700,701,709],{"__ignoreMap":77},[81,702,703,706],{"class":83,"line":84},[81,704,628],{"class":705},"sovSZ",[81,707,708],{"class":95},":\n",[81,710,711,714],{"class":83,"line":135},[81,712,713],{"class":95},"  - ",[81,715,716],{"class":91},"packages\u002F*\n",[10,718,719],{},"This file instructs pnpm where to find the packages in our monorepo. It links the packages together, avoids duplication, shares dependencies, and facilitates installation with a single command.",[10,721,722,723,725],{},"Even with a monorepo, each package should be treated as a standalone project, having its own ",[46,724,119],{},", dependencies, scripts, and operations.",[10,727,728],{},"Install dependencies from the root of the project:",[71,730,732],{"className":73,"code":731,"filename":119,"language":76,"meta":77,"style":77},"pnpm install\n",[46,733,734],{"__ignoreMap":77},[81,735,736,738],{"class":83,"line":84},[81,737,342],{"class":87},[81,739,740],{"class":91}," install\n",[10,742,743],{},"You'll see that pnpm recognizes 2 packages:",[71,745,747],{"className":552,"code":746,"filename":554,"language":555,"meta":77,"style":77},"Scope: all 2 workspace projects\n",[46,748,749],{"__ignoreMap":77},[81,750,751],{"class":83,"line":84},[81,752,746],{},[10,754,755],{},"In the next article, we will create our first component in our newly established monorepo.",[757,758,759],"style",{},"html pre.shiki code .snPdu, html code.shiki .snPdu{--shiki-light:#6F42C1;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sIIMD, html code.shiki .sIIMD{--shiki-light:#032F62;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sxrX7, html code.shiki .sxrX7{--shiki-light:#24292E;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sBjJW, html code.shiki .sBjJW{--shiki-light:#005CC5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s8jYJ, html code.shiki .s8jYJ{--shiki-light:#D73A49;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sovSZ, html code.shiki .sovSZ{--shiki-light:#22863A;--shiki-default:#22863A;--shiki-dark:#85E89D}",{"title":77,"searchDepth":135,"depth":135,"links":761},[762,763,764],{"id":37,"depth":135,"text":38},{"id":264,"depth":135,"text":265},{"id":537,"depth":135,"text":538},"1f6cf4af-8637-458d-93f8-52ac60dd8f87","2024-11-24","Start your monorepo journey! Learn how to set up a linter and formatter for streamlined coding and organizing your project.","md",null,{},"\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fgetting-started-with-monorepo-linter-and-formatter","---\ncontentId: 1f6cf4af-8637-458d-93f8-52ac60dd8f87\npart: 1\ntitle: Getting Started with Monorepo, Linter, and Formatter\ndescription: Start your monorepo journey! Learn how to set up a linter and formatter for streamlined coding and organizing your project.\ndate: 2024-11-24\nseriesSlug: the-complete-guide-to-building-a-vue-js-component-library\n---\n\nIn this series, we will begin from scratch. This is the optimal way to comprehend the process. We'll establish a **monorepo** and set up a **linter** and a **formatter**.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nThe process is versatile and can be applied to any project, not just a component library.\n::\n\n## Setting up the project\n\nA **monorepo** is a repository housing multiple projects. In our case, we will have the package `@barbapapazes\u002Fhuchet-vue`, two playgrounds, and a storybook. Employing a monorepo enables the management of all these projects within a single repository, facilitates code sharing, and allows for a single dependency installation, keeping everything synchronized and compatible. We could easily imagine adding more packages in the future, such as a custom **Tailwind CSS** configuration or a shared utility library.\n\nTo create a monorepo, we'll utilize [**pnpm workspaces**](https:\u002F\u002Fpnpm.io\u002Fworkspaces), a feature within the pnpm package manager that installs dependencies smartly, using hard links and symlinks to save disk space and time.\n\nFirst, create a new directory and initialize a new git repository:\n\n```bash [terminal]\nmkdir huchet-vue && cd huchet-vue && npm init -y\n```\n\nOpen this folder in your code editor and modify the `package.json` file:\n\n```json [package.json]\n{\n  \"name\": \"huchet-vue\",\n  \"version\": \"0.0.0\",\n  \"type\": \"module\",\n  \"private\": true\n}\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nSetting the `private` field to `true` in a `package.json` file prevents accidental publication to the npm registry. Our root `package.json` is for monorepo management rather than publication.\n::\n\nThis `package.json` is the primary file for our monorepo. Future packages will each have their own `package.json`. The main file will only include dependencies and scripts impacting the entire monorepo, not shared between packages.\n\nBefore proceeding, adjust a pnpm setting by creating a `.npmrc` file:\n\n```bash [package.json]\necho \"shamefully-hoist=true\" > .npmrc\n```\n\nThis setting allows pnpm to hoist dependencies to the root `node_modules` folder. While not default or recommended, it is necessary in our case.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nBy default, pnpm creates a semistrict `node_modules`, allowing access to undeclared dependencies only from within `node_modules`.\n::\n\n## Linter and formatter\n\nAdding a **linter** and a **formatter** ensures our code remains clean and consistent, a fundamental requirement for any project, especially a component library used by other developers.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nA **formatter** automatically formats your code according to set rules, while a **linter** analyzes code statically to detect potential errors and enforce rules.\n::\n\nCommonly, [**Prettier**](https:\u002F\u002Fprettier.io\u002F) is used as a formatter, and [**ESLint**](https:\u002F\u002Feslint.org\u002F) as a linter. Both have extensive plugins and configurations, but integrating them can be complex. As I'm not opinionated about code style, less configuration is better.\n\nFor this project, as with all my projects, we'll use the ESLint configuration by [Anthony Fu](https:\u002F\u002Fantfu.me\u002F). It's a highly opinionated setup using **ESLint** and [**Stylistic**](https:\u002F\u002Feslint.style\u002F).\n\nInstall it with a simple command:\n\n```bash [terminal]\nnpx @antfu\u002Feslint-config@latest && pnpm add -D typescript\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nThese are installed at the root of the monorepo to maintain a unified source of truth for linting and formatting, a common monorepo practice.\n::\n\nAdd two scripts to your `package.json` file:\n\n```json [package.json]\n{\n  \"scripts\": {\n    \"lint\": \"eslint .\",\n    \"lint:fix\": \"eslint --fix .\"\n  }\n}\n```\n\nUpdate the `eslint.config.ts` file to support **Vue**, **TypeScript**, and **Stylistic**:\n\n```typescript [eslint.config.ts]\nimport antfu from '@antfu\u002Feslint-config'\n\nexport default antfu({\n  stylistic: true,\n  vue: true,\n  typescript: true\n})\n```\n\nNow, you can lint your code:\n\n```bash [terminal]\npnpm run lint\n```\n\nAnd automatically fix issues:\n\n```bash [terminal]\npnpm run lint:fix\n```\n\n## Defining our monorepo\n\nWith the **linter** and **formatter** set up, we can start defining our monorepo.\n\nWe will have the following structure:\n\n```txt [Example]\n.\n├── .histoire\n│   └── package.json\n├── package.json\n├── packages\n│   └── huchet-vue\n│       └── package.json\n└── playground\n    ├── nuxt\n    │   └── package.json\n    └── vue\n        └── package.json\n```\n\nFor now, create the `packages` folder and the `huchet-vue` package with its `package.json` file. Additional packages will be developed in future parts of this series.\n\n```bash [package.json]\nmkdir -p packages\u002Fhuchet-vue\necho '{\\n\"name\": \"@barbapapazes\u002Fhuchet-vue\",\\n\"type\": \"module\",\\n\"version\": \"0.0.0\"\\n}' > packages\u002Fhuchet-vue\u002Fpackage.json\n```\n\nHaving two packages allows us to define them in a `pnpm-workspace.yaml` file at the root of our monorepo:\n\n```bash [pnpm-workspace.yaml]\necho 'packages:\\n  - packages\u002F*' > pnpm-workspace.yaml\n```\n\nEnsure `pnpm-workspace.yaml` file looks like:\n\n```yaml [pnpm-workspace.yaml]\npackages:\n  - packages\u002F*\n```\n\nThis file instructs pnpm where to find the packages in our monorepo. It links the packages together, avoids duplication, shares dependencies, and facilitates installation with a single command.\n\nEven with a monorepo, each package should be treated as a standalone project, having its own `package.json`, dependencies, scripts, and operations.\n\nInstall dependencies from the root of the project:\n\n```bash [package.json]\npnpm install\n```\n\nYou'll see that pnpm recognizes 2 packages:\n\n```txt [Example]\nScope: all 2 workspace projects\n```\n\nIn the next article, we will create our first component in our newly established monorepo.\n",{"title":5,"description":767},"the-complete-guide-to-building-a-vue-js-component-library",{"loc":771},"series\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fgetting-started-with-monorepo-linter-and-formatter","y1jMOvTbmqII4QTnf6HlJrDP0Ky19zzNY2mIAPG_Gyc",{"overview":779,"chapters":977},{"id":780,"title":781,"body":782,"contentId":960,"date":766,"description":961,"extension":768,"github":962,"meetTheInstructor":964,"meta":965,"navigation":453,"part":769,"path":966,"rawbody":967,"robots":769,"schemaOrg":769,"seo":968,"seriesSlug":774,"sitemap":969,"stem":970,"subtitle":971,"topics":972,"__hash__":976},"series\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library.md","The Complete Guide to Building a Vue.js Component Library",{"type":7,"value":783,"toc":956},[784,787,790,802,806,809,823,827,830,943,946,950],[10,785,786],{},"Welcome! 👋",[10,788,789],{},"Initially, this series was intended to be a single article, but it soon became apparent that it would be too lengthy. Even GitHub didn't want to display it in the file tab of pull requests. Therefore, I decided to divide it into multiple articles to make it more digestible and to focus on each part individually.",[10,791,792,793,797,798],{},"This series is somewhat of a sequel to the article ",[58,794,796],{"href":795},"\u002Fposts\u002Fthe-simplest-method-to-create-a-vue-js-component-library","The Simplest Method to Create a Vue.js Component Library"," but adopts a more professional approach. ",[799,800,801],"em",{},"You will learn how the most popular component libraries are constructed behind the scenes and how to create your own.",[803,804],"callout-read-more",{"id":805},"f9754148-40bd-4df2-a144-f686e894b200",[10,807,808],{},"While it's still my preferred method when I am certain about what I want to achieve, I also received feedback from readers seeking more custom behavior and requiring more complex features.",[10,810,811,812,817,818,25],{},"That's understandable. While ",[58,813,816],{"href":814,"rel":815},"https:\u002F\u002Fgithub.com\u002Funjs\u002Funbuild",[62],"unbuild"," is a powerful tool, it cannot match the flexibility, plugin ecosystem, and adoption of ",[58,819,822],{"href":820,"rel":821},"https:\u002F\u002Fvite.dev\u002F",[62],"Vite",[35,824,826],{"id":825},"what-to-expect","What to expect",[10,828,829],{},"Throughout this series, we will address the following topics:",[831,832,833,843,874,891,908,914,926],"ol",{},[834,835,836,838,839,842],"li",{},[14,837,5],{},": We'll set up a monorepo to manage our component library and all the tools necessary to ensure a good development experience. We'll also configure ",[58,840,301],{"href":297,"rel":841},[62]," to ensure code consistency.",[834,844,845,848,849,420,854,424,858,863,864,314,869,25],{},[14,846,847],{},"Building a First Component with Vue.js and Tailwind CSS",": We'll create our first component with ",[58,850,853],{"href":851,"rel":852},"https:\u002F\u002Fvuejs.org\u002F",[62],"Vue.js",[58,855,52],{"href":856,"rel":857},"https:\u002F\u002Ftailwindcss.com\u002F",[62],[58,859,862],{"href":860,"rel":861},"https:\u002F\u002Fwww.tailwind-variants.org\u002F",[62],"Tailwind Variants"," using the most advanced and powerful techniques employed in popular component libraries like ",[58,865,868],{"href":866,"rel":867},"https:\u002F\u002Fwww.radix-vue.com\u002F",[62],"Radix Vue",[58,870,873],{"href":871,"rel":872},"https:\u002F\u002Fui.nuxt.com\u002F",[62],"Nuxt UI",[834,875,876,879,880,884,885,890],{},[14,877,878],{},"A Better Development Experience with TypeScript and TSConfig",": We'll enhance our development experience by adding ",[58,881,423],{"href":882,"rel":883},"https:\u002F\u002Fwww.typescriptlang.org\u002F",[62]," to our component library and configuring ",[58,886,889],{"href":887,"rel":888},"https:\u002F\u002Fwww.typescriptlang.org\u002Ftsconfig",[62],"TSConfig"," to ensure that our components are typed correctly and that we can take full advantage of TypeScript's features.",[834,892,893,896,897,314,902,907],{},[14,894,895],{},"Automatic Component Testing with Vitest and Testing Library",": We'll write tests for our components using ",[58,898,901],{"href":899,"rel":900},"https:\u002F\u002Fvitest.dev\u002Fguide\u002F",[62],"Vitest",[58,903,906],{"href":904,"rel":905},"https:\u002F\u002Ftesting-library.com\u002F",[62],"Testing Library"," to ensure that our components function as expected. This is crucial for a professional component library that remains reliable over time.",[834,909,910,913],{},[14,911,912],{},"Delivering Components Continuously and with Confidence",": We'll establish a continuous integration process to ensure that our components are always delivered with confidence. For every commit of every branch, we'll run our tests to verify everything is functioning correctly. We'll also establish a release process to publish our components to npm.",[834,915,916,919,920,925],{},[14,917,918],{},"Creating a Playground and a Storybook for Components",": We'll create a playground to test our components in a real environment and a storybook with ",[58,921,924],{"href":922,"rel":923},"https:\u002F\u002Fhistoire.dev\u002F",[62],"Histoire"," to document them. This will enable us to share our components with other developers and to test them in various scenarios, both in isolation and in combination.",[834,927,928,931,932,21,937,942],{},[14,929,930],{},"Enhancing Integration with Unplugin and Nuxt Module",": We'll enhance the integration of our component library with the ecosystem by creating a Vite plugin with ",[58,933,936],{"href":934,"rel":935},"https:\u002F\u002Fgithub.com\u002Funplugin\u002Funplugin-vue-components",[62],"Unplugin Vue Components",[58,938,941],{"href":939,"rel":940},"https:\u002F\u002Fnuxt.com\u002Fdocs\u002Fguide\u002Fgoing-further\u002Fmodules",[62],"Nuxt module"," to utilize our components in a Nuxt application.",[10,944,945],{},"By the end of this series, you will have a complete Vue.js component library that you can use in your projects or share with the community, like a professional developer. Isn't that exciting? 😎",[35,947,949],{"id":948},"chapters","Chapters",[951,952],"series-chapters-list",{"className":953},[954,955],"mx-auto","max-w-5xl",{"title":77,"searchDepth":135,"depth":135,"links":957},[958,959],{"id":825,"depth":135,"text":826},{"id":948,"depth":135,"text":949},"55d2cdcf-ba27-4bfe-9bc1-492e866ff3b1","Discover how to build a Vue.js component library using Vite with a guide that covers essential techniques for professional web development.",{"name":632,"repository":963},"barbapapazes\u002Fhuchet-vue","I create this series because I love \u003Cstrong>Vue.js\u003C\u002Fstrong> and, for years, I have been unable to find a complete, up-to-date, and \u003Cstrong>professional guide\u003C\u002Fstrong> on how to build a Vue.js component library and want more software developers to feel empowered to create their own.",{},"\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library","---\ncontentId: 55d2cdcf-ba27-4bfe-9bc1-492e866ff3b1\ntitle: The Complete Guide to Building a Vue.js Component Library\nsubtitle: The most advanced and professional course to build a Vue.js component library with Vite.\ndescription: Discover how to build a Vue.js component library using Vite with a guide that covers essential techniques for professional web development.\ndate: 2024-11-24\ntopics:\n  - vue\n  - vite\n  - component library\ngithub:\n  name: huchet-vue\n  repository: barbapapazes\u002Fhuchet-vue\nmeetTheInstructor: I create this series because I love \u003Cstrong>Vue.js\u003C\u002Fstrong> and, for years, I have been unable to find a complete, up-to-date, and \u003Cstrong>professional guide\u003C\u002Fstrong> on how to build a Vue.js component library and want more software developers to feel empowered to create their own.\nseriesSlug: the-complete-guide-to-building-a-vue-js-component-library\n---\n\nWelcome! 👋\n\nInitially, this series was intended to be a single article, but it soon became apparent that it would be too lengthy. Even GitHub didn't want to display it in the file tab of pull requests. Therefore, I decided to divide it into multiple articles to make it more digestible and to focus on each part individually.\n\nThis series is somewhat of a sequel to the article [The Simplest Method to Create a Vue.js Component Library](\u002Fposts\u002Fthe-simplest-method-to-create-a-vue-js-component-library) but adopts a more professional approach. _You will learn how the most popular component libraries are constructed behind the scenes and how to create your own._\n\n\u003CCalloutReadMore id=\"f9754148-40bd-4df2-a144-f686e894b200\" \u002F>\n\nWhile it's still my preferred method when I am certain about what I want to achieve, I also received feedback from readers seeking more custom behavior and requiring more complex features.\n\nThat's understandable. While [unbuild](https:\u002F\u002Fgithub.com\u002Funjs\u002Funbuild) is a powerful tool, it cannot match the flexibility, plugin ecosystem, and adoption of [Vite](https:\u002F\u002Fvite.dev\u002F).\n\n## What to expect\n\nThroughout this series, we will address the following topics:\n\n1. **Getting Started with Monorepo, Linter, and Formatter**: We'll set up a monorepo to manage our component library and all the tools necessary to ensure a good development experience. We'll also configure [ESLint](https:\u002F\u002Feslint.org\u002F) to ensure code consistency.\n2. **Building a First Component with Vue.js and Tailwind CSS**: We'll create our first component with [Vue.js](https:\u002F\u002Fvuejs.org\u002F), [Tailwind CSS](https:\u002F\u002Ftailwindcss.com\u002F), and [Tailwind Variants](https:\u002F\u002Fwww.tailwind-variants.org\u002F) using the most advanced and powerful techniques employed in popular component libraries like [Radix Vue](https:\u002F\u002Fwww.radix-vue.com\u002F) and [Nuxt UI](https:\u002F\u002Fui.nuxt.com\u002F).\n3. **A Better Development Experience with TypeScript and TSConfig**: We'll enhance our development experience by adding [TypeScript](https:\u002F\u002Fwww.typescriptlang.org\u002F) to our component library and configuring [TSConfig](https:\u002F\u002Fwww.typescriptlang.org\u002Ftsconfig) to ensure that our components are typed correctly and that we can take full advantage of TypeScript's features.\n4. **Automatic Component Testing with Vitest and Testing Library**: We'll write tests for our components using [Vitest](https:\u002F\u002Fvitest.dev\u002Fguide\u002F) and [Testing Library](https:\u002F\u002Ftesting-library.com\u002F) to ensure that our components function as expected. This is crucial for a professional component library that remains reliable over time.\n5. **Delivering Components Continuously and with Confidence**: We'll establish a continuous integration process to ensure that our components are always delivered with confidence. For every commit of every branch, we'll run our tests to verify everything is functioning correctly. We'll also establish a release process to publish our components to npm.\n6. **Creating a Playground and a Storybook for Components**: We'll create a playground to test our components in a real environment and a storybook with [Histoire](https:\u002F\u002Fhistoire.dev\u002F) to document them. This will enable us to share our components with other developers and to test them in various scenarios, both in isolation and in combination.\n7. **Enhancing Integration with Unplugin and Nuxt Module**: We'll enhance the integration of our component library with the ecosystem by creating a Vite plugin with [Unplugin Vue Components](https:\u002F\u002Fgithub.com\u002Funplugin\u002Funplugin-vue-components) and a [Nuxt module](https:\u002F\u002Fnuxt.com\u002Fdocs\u002Fguide\u002Fgoing-further\u002Fmodules) to utilize our components in a Nuxt application.\n\nBy the end of this series, you will have a complete Vue.js component library that you can use in your projects or share with the community, like a professional developer. Isn't that exciting? 😎\n\n## Chapters\n\n::series-chapters-list\n---\nclass: mx-auto max-w-5xl\n---\n::\n",{"title":781,"description":961},{"loc":966},"series\u002Fthe-complete-guide-to-building-a-vue-js-component-library","The most advanced and professional course to build a Vue.js component library with Vite.",[973,974,975],"vue","vite","component library","2VSSnBlkuSLlt05n9MySLBFt6vBkgd7691eX-TK2cTs",[978,979,983,987,991,995,999],{"contentId":765,"title":5,"description":767,"path":771,"part":84,"github":769,"topics":769},{"contentId":980,"title":847,"description":981,"path":982,"part":135,"github":769,"topics":769},"e9f57d8c-a722-4fd7-b326-61af0ea9dbd4","Creating a simple Vue.js button component using Tailwind CSS for styling and variants, along with step-by-step library build configuration using Vite.","\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fbuilding-a-first-component-with-vuejs-and-tailwind-css",{"contentId":984,"title":878,"description":985,"path":986,"part":150,"github":769,"topics":769},"c2d651b0-4487-472d-b55a-b3cf195bcba8","Learn how to configure TypeScript with multiple contexts and generate types for a library to expose types to developers.","\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fa-better-development-experience-with-typescript-and-tsconfig",{"contentId":988,"title":895,"description":989,"path":990,"part":163,"github":769,"topics":769},"e95133e4-2362-4aa3-bd3d-b70afc6c4d4e","Learn how to automate testing for Vue.js components using Vitest and Testing Library for efficient and user-focused testing.","\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fautomatic-component-testing-with-vitest-and-testing-library",{"contentId":992,"title":912,"description":993,"path":994,"part":176,"github":769,"topics":769},"34bd87b4-cefd-44bb-affe-21e5e0fe7d56","Implement a CI pipeline with GitHub Actions and automate the release process to npm for Vue.js component libraries.","\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fdelivering-components-continuously-and-with-confidence",{"contentId":996,"title":918,"description":997,"path":998,"part":187,"github":769,"topics":769},"53bbc0ae-a7b8-49d3-8ae6-73b585c43efc","Learn how to create a playground and use Histoire to visualize and document your components in both isolated and combined scenarios.","\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fcreating-a-playground-and-a-storybook-for-components",{"contentId":1000,"title":930,"description":1001,"path":1002,"part":496,"github":769,"topics":769},"8b808104-15ac-42ca-9535-cef0996ddf66","Discover how to seamlessly integrate a Vue.js component library using Unplugin Vue Components and Nuxt Module, enhancing usability and developer experience.","\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fenhancing-integration-with-unplugin-and-nuxt-module",1795016694445]