[{"data":1,"prerenderedAt":1510},["ShallowReactive",2],{"series-\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fbuilding-a-first-component-with-vuejs-and-tailwind-css":3,"series-context-\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library":1287},{"id":4,"title":5,"body":6,"contentId":1275,"date":1276,"description":1277,"extension":394,"github":1278,"meetTheInstructor":1278,"meta":1279,"navigation":287,"part":186,"path":1280,"rawbody":1281,"robots":1278,"schemaOrg":1278,"seo":1282,"seriesSlug":1283,"sitemap":1284,"stem":1285,"subtitle":1278,"topics":1278,"__hash__":1286},"series\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fbuilding-a-first-component-with-vuejs-and-tailwind-css.md","Building a First Component with Vue.js and Tailwind CSS",{"type":7,"value":8,"toc":1269},"minimark",[9,18,39,44,52,95,106,130,137,141,144,147,157,225,237,257,379,396,399,508,517,580,596,599,672,675,711,714,718,729,741,754,757,773,779,972,975,978,997,1003,1013,1025,1028,1046,1053,1065,1068,1108,1111,1126,1136,1140,1155,1214,1239,1258,1265],[10,11,12,13,17],"p",{},"With our ",[14,15,16],"strong",{},"Vue.js"," component library set up, it's time to build our first component: a simple button. This exercise will help us understand how to structure our components.",[10,19,20,21,30,31,38],{},"We'll use ",[22,23,27],"a",{"href":24,"rel":25},"https:\u002F\u002Ftailwindcss.com\u002F",[26],"nofollow",[14,28,29],{},"Tailwind CSS"," and ",[22,32,35],{"href":33,"rel":34},"https:\u002F\u002Fwww.tailwind-variants.org\u002F",[26],[14,36,37],{},"Tailwind Variants"," for styling. Tailwind Variants helps organize Tailwind CSS classes in a structured way to create and combine variants.",[40,41,43],"h2",{"id":42},"setting-up-the-package","Setting up the package",[10,45,46,47,51],{},"Navigate to ",[48,49,50],"code",{},"packages\u002Fhuchet-vue"," and install the necessary dependencies:",[53,54,60],"pre",{"className":55,"code":56,"filename":57,"language":58,"meta":59,"style":59},"language-bash shiki shiki-themes github-light github-light github-dark","cd packages\u002Fhuchet-vue && pnpm add -D vue vite\n","terminal","bash","",[48,61,62],{"__ignoreMap":59},[63,64,67,71,75,79,83,86,89,92],"span",{"class":65,"line":66},"line",1,[63,68,70],{"class":69},"sBjJW","cd",[63,72,74],{"class":73},"sIIMD"," packages\u002Fhuchet-vue",[63,76,78],{"class":77},"sxrX7"," && ",[63,80,82],{"class":81},"snPdu","pnpm",[63,84,85],{"class":73}," add",[63,87,88],{"class":69}," -D",[63,90,91],{"class":73}," vue",[63,93,94],{"class":73}," vite\n",[10,96,97,98,101,102,105],{},"Then, create a ",[48,99,100],{},"src"," folder with the ",[48,103,104],{},"Button\u002FButton.vue"," component:",[53,107,109],{"className":55,"code":108,"filename":104,"language":58,"meta":59,"style":59},"mkdir -p src\u002FButton && touch src\u002FButton\u002FButton.vue\n",[48,110,111],{"__ignoreMap":59},[63,112,113,116,119,122,124,127],{"class":65,"line":66},[63,114,115],{"class":81},"mkdir",[63,117,118],{"class":69}," -p",[63,120,121],{"class":73}," src\u002FButton",[63,123,78],{"class":77},[63,125,126],{"class":81},"touch",[63,128,129],{"class":73}," src\u002FButton\u002FButton.vue\n",[10,131,132,133,136],{},"Open the ",[48,134,135],{},"Button.vue"," file and let's start writing our component.",[40,138,140],{"id":139},"writing-the-button-component","Writing the button component",[10,142,143],{},"For our example, we'll create a button with two variants: solid and outline. The solid variant will feature a background color, and the outline variant will include a border.",[10,145,146],{},"To ensure class non-conflict and simplify refactoring, maintainability, readability, and structure, we'll use Tailwind Variants. We'll organize our classes into an object, and Tailwind Variants will apply the correct classes based on props.",[10,148,149,150,153,154,156],{},"Add a ",[48,151,152],{},"script"," tag at the top of the ",[48,155,135],{}," file:",[53,158,162],{"className":159,"code":160,"filename":135,"language":161,"meta":59,"style":59},"language-vue shiki shiki-themes github-light github-light github-dark","\u003Cscript lang=\"ts\">\nimport type { VariantProps } from 'tailwind-variants'\nimport { tv } from 'tailwind-variants'\n\u003C\u002Fscript>\n","vue",[48,163,164,184,203,215],{"__ignoreMap":59},[63,165,166,169,172,175,178,181],{"class":65,"line":66},[63,167,168],{"class":77},"\u003C",[63,170,152],{"class":171},"sovSZ",[63,173,174],{"class":81}," lang",[63,176,177],{"class":77},"=",[63,179,180],{"class":73},"\"ts\"",[63,182,183],{"class":77},">\n",[63,185,187,191,194,197,200],{"class":65,"line":186},2,[63,188,190],{"class":189},"s8jYJ","import",[63,192,193],{"class":189}," type",[63,195,196],{"class":77}," { VariantProps } ",[63,198,199],{"class":189},"from",[63,201,202],{"class":73}," 'tailwind-variants'\n",[63,204,206,208,211,213],{"class":65,"line":205},3,[63,207,190],{"class":189},[63,209,210],{"class":77}," { tv } ",[63,212,199],{"class":189},[63,214,202],{"class":73},[63,216,218,221,223],{"class":65,"line":217},4,[63,219,220],{"class":77},"\u003C\u002F",[63,222,152],{"class":171},[63,224,183],{"class":77},[226,227,230],"callout",{"color":228,"icon":229},"primary","i-ph-info-duotone",[10,231,232,233,236],{},"Do not add the ",[48,234,235],{},"setup"," attribute. This omission is intentional.",[10,238,239,240,243,244,30,247,250,251,253,254,256],{},"The ",[48,241,242],{},"tv"," function is a helper for organizing classes. It accepts an object with ",[48,245,246],{},"base",[48,248,249],{},"variants"," keys. The ",[48,252,246],{}," is a string of shared classes, whereas ",[48,255,249],{}," is a record with variant keys and class values.",[53,258,261],{"className":159,"code":259,"filename":260,"language":161,"meta":59,"style":59},"\u003Cscript lang=\"ts\">\n\u002F\u002F ...\n\nconst button = tv({\n  base: 'border-2 px-2.5 py-1.5 text-sm font-semibold focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2',\n  variants: {\n    variant: {\n      solid: 'border-transparent bg-blue-500 text-white hover:bg-blue-600 active:bg-blue-700',\n      outline: 'border-blue-500 text-blue-500 hover:bg-blue-50 active:bg-blue-100',\n    }\n  }\n})\n\u003C\u002Fscript>\n","Example",[48,262,263,277,283,289,306,318,324,330,341,352,358,364,370],{"__ignoreMap":59},[63,264,265,267,269,271,273,275],{"class":65,"line":66},[63,266,168],{"class":77},[63,268,152],{"class":171},[63,270,174],{"class":81},[63,272,177],{"class":77},[63,274,180],{"class":73},[63,276,183],{"class":77},[63,278,279],{"class":65,"line":186},[63,280,282],{"class":281},"sCsY4","\u002F\u002F ...\n",[63,284,285],{"class":65,"line":205},[63,286,288],{"emptyLinePlaceholder":287},true,"\n",[63,290,291,294,297,300,303],{"class":65,"line":217},[63,292,293],{"class":189},"const",[63,295,296],{"class":69}," button",[63,298,299],{"class":189}," =",[63,301,302],{"class":81}," tv",[63,304,305],{"class":77},"({\n",[63,307,309,312,315],{"class":65,"line":308},5,[63,310,311],{"class":77},"  base: ",[63,313,314],{"class":73},"'border-2 px-2.5 py-1.5 text-sm font-semibold focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2'",[63,316,317],{"class":77},",\n",[63,319,321],{"class":65,"line":320},6,[63,322,323],{"class":77},"  variants: {\n",[63,325,327],{"class":65,"line":326},7,[63,328,329],{"class":77},"    variant: {\n",[63,331,333,336,339],{"class":65,"line":332},8,[63,334,335],{"class":77},"      solid: ",[63,337,338],{"class":73},"'border-transparent bg-blue-500 text-white hover:bg-blue-600 active:bg-blue-700'",[63,340,317],{"class":77},[63,342,344,347,350],{"class":65,"line":343},9,[63,345,346],{"class":77},"      outline: ",[63,348,349],{"class":73},"'border-blue-500 text-blue-500 hover:bg-blue-50 active:bg-blue-100'",[63,351,317],{"class":77},[63,353,355],{"class":65,"line":354},10,[63,356,357],{"class":77},"    }\n",[63,359,361],{"class":65,"line":360},11,[63,362,363],{"class":77},"  }\n",[63,365,367],{"class":65,"line":366},12,[63,368,369],{"class":77},"})\n",[63,371,373,375,377],{"class":65,"line":372},13,[63,374,220],{"class":77},[63,376,152],{"class":171},[63,378,183],{"class":77},[10,380,381,382,384,385,388,389,30,392,395],{},"In the ",[48,383,249],{}," key, you could also include more keys like ",[48,386,387],{},"size"," with ",[48,390,391],{},"sm",[48,393,394],{},"md"," variants.",[10,397,398],{},"Next, extract the variants for use in our component props:",[53,400,402],{"className":159,"code":401,"filename":260,"language":161,"meta":59,"style":59},"\u003Cscript lang=\"ts\">\n\u002F\u002F ...\n\ntype ButtonVariantProps = VariantProps\u003Ctypeof button>\n\nexport interface ButtonProps {\n  label?: string\n  variant?: ButtonVariantProps['variant']\n}\n\u003C\u002Fscript>\n",[48,403,404,418,422,426,447,451,465,477,495,500],{"__ignoreMap":59},[63,405,406,408,410,412,414,416],{"class":65,"line":66},[63,407,168],{"class":77},[63,409,152],{"class":171},[63,411,174],{"class":81},[63,413,177],{"class":77},[63,415,180],{"class":73},[63,417,183],{"class":77},[63,419,420],{"class":65,"line":186},[63,421,282],{"class":281},[63,423,424],{"class":65,"line":205},[63,425,288],{"emptyLinePlaceholder":287},[63,427,428,431,434,436,439,441,444],{"class":65,"line":217},[63,429,430],{"class":189},"type",[63,432,433],{"class":81}," ButtonVariantProps",[63,435,299],{"class":189},[63,437,438],{"class":81}," VariantProps",[63,440,168],{"class":77},[63,442,443],{"class":189},"typeof",[63,445,446],{"class":77}," button>\n",[63,448,449],{"class":65,"line":308},[63,450,288],{"emptyLinePlaceholder":287},[63,452,453,456,459,462],{"class":65,"line":320},[63,454,455],{"class":189},"export",[63,457,458],{"class":189}," interface",[63,460,461],{"class":81}," ButtonProps",[63,463,464],{"class":77}," {\n",[63,466,467,471,474],{"class":65,"line":326},[63,468,470],{"class":469},"sP4rz","  label",[63,472,473],{"class":189},"?:",[63,475,476],{"class":69}," string\n",[63,478,479,482,484,486,489,492],{"class":65,"line":332},[63,480,481],{"class":469},"  variant",[63,483,473],{"class":189},[63,485,433],{"class":81},[63,487,488],{"class":77},"[",[63,490,491],{"class":73},"'variant'",[63,493,494],{"class":77},"]\n",[63,496,497],{"class":65,"line":343},[63,498,499],{"class":77},"}\n",[63,501,502,504,506],{"class":65,"line":354},[63,503,220],{"class":77},[63,505,152],{"class":171},[63,507,183],{"class":77},[10,509,510,511,513,514,516],{},"Then open a new ",[48,512,152],{}," tag with the ",[48,515,235],{}," attribute:",[53,518,520],{"className":159,"code":519,"filename":260,"language":161,"meta":59,"style":59},"\u003Cscript setup lang=\"ts\">\nwithDefaults(defineProps\u003CButtonProps>(), {\n  variant: 'solid',\n})\n\u003C\u002Fscript>\n",[48,521,522,539,558,568,572],{"__ignoreMap":59},[63,523,524,526,528,531,533,535,537],{"class":65,"line":66},[63,525,168],{"class":77},[63,527,152],{"class":171},[63,529,530],{"class":81}," setup",[63,532,174],{"class":81},[63,534,177],{"class":77},[63,536,180],{"class":73},[63,538,183],{"class":77},[63,540,541,544,547,550,552,555],{"class":65,"line":186},[63,542,543],{"class":81},"withDefaults",[63,545,546],{"class":77},"(",[63,548,549],{"class":81},"defineProps",[63,551,168],{"class":77},[63,553,554],{"class":81},"ButtonProps",[63,556,557],{"class":77},">(), {\n",[63,559,560,563,566],{"class":65,"line":205},[63,561,562],{"class":77},"  variant: ",[63,564,565],{"class":73},"'solid'",[63,567,317],{"class":77},[63,569,570],{"class":65,"line":217},[63,571,369],{"class":77},[63,573,574,576,578],{"class":65,"line":308},[63,575,220],{"class":77},[63,577,152],{"class":171},[63,579,183],{"class":77},[10,581,582,583,585,586,588,589,591,592,595],{},"We split the ",[48,584,152],{}," tag into two parts to enable named exports. The ",[48,587,554],{}," interface is used in the ",[48,590,549],{}," function and is exported so developers can extend it to create a new component. This detail is crucial for building a robust ",[14,593,594],{},"component library",".",[10,597,598],{},"Add the component's template:",[53,600,602],{"className":159,"code":601,"filename":260,"language":161,"meta":59,"style":59},"\u003Ctemplate>\n  \u003Cbutton :class=\"button({ variant })\">\n    \u003Cslot>\n      {{ label }}\n    \u003C\u002Fslot>\n  \u003C\u002Fbutton>\n\u003C\u002Ftemplate>\n",[48,603,604,613,631,641,646,655,664],{"__ignoreMap":59},[63,605,606,608,611],{"class":65,"line":66},[63,607,168],{"class":77},[63,609,610],{"class":171},"template",[63,612,183],{"class":77},[63,614,615,618,621,624,626,629],{"class":65,"line":186},[63,616,617],{"class":77},"  \u003C",[63,619,620],{"class":171},"button",[63,622,623],{"class":81}," :class",[63,625,177],{"class":77},[63,627,628],{"class":73},"\"button({ variant })\"",[63,630,183],{"class":77},[63,632,633,636,639],{"class":65,"line":205},[63,634,635],{"class":77},"    \u003C",[63,637,638],{"class":171},"slot",[63,640,183],{"class":77},[63,642,643],{"class":65,"line":217},[63,644,645],{"class":77},"      {{ label }}\n",[63,647,648,651,653],{"class":65,"line":308},[63,649,650],{"class":77},"    \u003C\u002F",[63,652,638],{"class":171},[63,654,183],{"class":77},[63,656,657,660,662],{"class":65,"line":320},[63,658,659],{"class":77},"  \u003C\u002F",[63,661,620],{"class":171},[63,663,183],{"class":77},[63,665,666,668,670],{"class":65,"line":326},[63,667,220],{"class":77},[63,669,610],{"class":171},[63,671,183],{"class":77},[10,673,674],{},"Our component is ready to use:",[53,676,680],{"className":677,"code":678,"filename":260,"language":679,"meta":59,"style":59},"language-html shiki shiki-themes github-light github-light github-dark","\u003CButton variant=\"outline\" label=\"Click me\" \u002F>\n","html",[48,681,682],{"__ignoreMap":59},[63,683,684,686,689,692,694,697,700,702,705,709],{"class":65,"line":66},[63,685,168],{"class":77},[63,687,688],{"class":171},"Button",[63,690,691],{"class":81}," variant",[63,693,177],{"class":77},[63,695,696],{"class":73},"\"outline\"",[63,698,699],{"class":81}," label",[63,701,177],{"class":77},[63,703,704],{"class":73},"\"Click me\"",[63,706,708],{"class":707},"sPrNH"," \u002F",[63,710,183],{"class":77},[10,712,713],{},"However, it's not usable until we build our component library.",[40,715,717],{"id":716},"building-the-component-library","Building the component library",[10,719,720,721,724,725,728],{},"Next, we'll build the component library. Start by creating a ",[48,722,723],{},"vite.config.ts"," file in the ",[48,726,727],{},"huchet-vue"," package root:",[53,730,732],{"className":55,"code":731,"filename":723,"language":58,"meta":59,"style":59},"touch vite.config.ts\n",[48,733,734],{"__ignoreMap":59},[63,735,736,738],{"class":65,"line":66},[63,737,126],{"class":81},[63,739,740],{"class":73}," vite.config.ts\n",[10,742,743,744,747,748,750,751,753],{},"This configuration instructs ",[14,745,746],{},"Vite"," how to transpile our ",[14,749,16],{}," components into JavaScript that can be used in other projects. By default, ",[14,752,746],{}," caters to web applications, not libraries, so we'll adjust it for our needs.",[10,755,756],{},"Install the necessary plugin:",[53,758,760],{"className":55,"code":759,"filename":57,"language":58,"meta":59,"style":59},"pnpm add -D @vitejs\u002Fplugin-vue\n",[48,761,762],{"__ignoreMap":59},[63,763,764,766,768,770],{"class":65,"line":66},[63,765,82],{"class":81},[63,767,85],{"class":73},[63,769,88],{"class":69},[63,771,772],{"class":73}," @vitejs\u002Fplugin-vue\n",[10,774,775,776,778],{},"Edit the ",[48,777,723],{}," file with the following configuration:",[53,780,784],{"className":781,"code":782,"filename":723,"language":783,"meta":59,"style":59},"language-ts shiki shiki-themes github-light github-light github-dark","import Vue from '@vitejs\u002Fplugin-vue'\nimport { defineConfig } from 'vite'\n\nexport default defineConfig({\n  plugins: [Vue()],\n  build: {\n    lib: {\n      formats: ['es'],\n      name: 'huchet-vue',\n      fileName: (_, name) => `${name}.mjs`,\n      entry: {\n        index: resolve(__dirname, 'src\u002Findex.ts'),\n      },\n    },\n    rollupOptions: {\n      external: ['vue', 'tailwind-variants'],\n    },\n  },\n})\n","ts",[48,785,786,798,810,814,826,837,842,847,858,868,901,906,923,928,934,940,956,961,967],{"__ignoreMap":59},[63,787,788,790,793,795],{"class":65,"line":66},[63,789,190],{"class":189},[63,791,792],{"class":77}," Vue ",[63,794,199],{"class":189},[63,796,797],{"class":73}," '@vitejs\u002Fplugin-vue'\n",[63,799,800,802,805,807],{"class":65,"line":186},[63,801,190],{"class":189},[63,803,804],{"class":77}," { defineConfig } ",[63,806,199],{"class":189},[63,808,809],{"class":73}," 'vite'\n",[63,811,812],{"class":65,"line":205},[63,813,288],{"emptyLinePlaceholder":287},[63,815,816,818,821,824],{"class":65,"line":217},[63,817,455],{"class":189},[63,819,820],{"class":189}," default",[63,822,823],{"class":81}," defineConfig",[63,825,305],{"class":77},[63,827,828,831,834],{"class":65,"line":308},[63,829,830],{"class":77},"  plugins: [",[63,832,833],{"class":81},"Vue",[63,835,836],{"class":77},"()],\n",[63,838,839],{"class":65,"line":320},[63,840,841],{"class":77},"  build: {\n",[63,843,844],{"class":65,"line":326},[63,845,846],{"class":77},"    lib: {\n",[63,848,849,852,855],{"class":65,"line":332},[63,850,851],{"class":77},"      formats: [",[63,853,854],{"class":73},"'es'",[63,856,857],{"class":77},"],\n",[63,859,860,863,866],{"class":65,"line":343},[63,861,862],{"class":77},"      name: ",[63,864,865],{"class":73},"'huchet-vue'",[63,867,317],{"class":77},[63,869,870,873,876,879,882,885,888,891,894,896,899],{"class":65,"line":354},[63,871,872],{"class":81},"      fileName",[63,874,875],{"class":77},": (",[63,877,878],{"class":469},"_",[63,880,881],{"class":77},", ",[63,883,884],{"class":469},"name",[63,886,887],{"class":77},") ",[63,889,890],{"class":189},"=>",[63,892,893],{"class":73}," `${",[63,895,884],{"class":77},[63,897,898],{"class":73},"}.mjs`",[63,900,317],{"class":77},[63,902,903],{"class":65,"line":360},[63,904,905],{"class":77},"      entry: {\n",[63,907,908,911,914,917,920],{"class":65,"line":366},[63,909,910],{"class":77},"        index: ",[63,912,913],{"class":81},"resolve",[63,915,916],{"class":77},"(__dirname, ",[63,918,919],{"class":73},"'src\u002Findex.ts'",[63,921,922],{"class":77},"),\n",[63,924,925],{"class":65,"line":372},[63,926,927],{"class":77},"      },\n",[63,929,931],{"class":65,"line":930},14,[63,932,933],{"class":77},"    },\n",[63,935,937],{"class":65,"line":936},15,[63,938,939],{"class":77},"    rollupOptions: {\n",[63,941,943,946,949,951,954],{"class":65,"line":942},16,[63,944,945],{"class":77},"      external: [",[63,947,948],{"class":73},"'vue'",[63,950,881],{"class":77},[63,952,953],{"class":73},"'tailwind-variants'",[63,955,857],{"class":77},[63,957,959],{"class":65,"line":958},17,[63,960,933],{"class":77},[63,962,964],{"class":65,"line":963},18,[63,965,966],{"class":77},"  },\n",[63,968,970],{"class":65,"line":969},19,[63,971,369],{"class":77},[10,973,974],{},"We choose not to include Vue.js and Tailwind Variants in the final bundle for flexibility, allowing users to use their versions. This also avoid duplication in the final bundle if the user already has these dependencies.",[10,976,977],{},"Add them as peer dependencies:",[53,979,981],{"className":55,"code":980,"filename":57,"language":58,"meta":59,"style":59},"pnpm add --save-peer vue tailwind-variants\n",[48,982,983],{"__ignoreMap":59},[63,984,985,987,989,992,994],{"class":65,"line":66},[63,986,82],{"class":81},[63,988,85],{"class":73},[63,990,991],{"class":69}," --save-peer",[63,993,91],{"class":73},[63,995,996],{"class":73}," tailwind-variants\n",[226,998,1000],{"color":999,"icon":229},"info",[10,1001,1002],{},"A peer dependency isn't installed by the package but should be present in the user's project. This flexibility is especially useful when a package may operate in varied contexts.",[10,1004,1005,1006,1009,1010,1012],{},"Create the ",[48,1007,1008],{},"src\u002Findex.ts"," file, as referenced in ",[48,1011,723],{},":",[53,1014,1016],{"className":55,"code":1015,"filename":723,"language":58,"meta":59,"style":59},"touch src\u002Findex.ts\n",[48,1017,1018],{"__ignoreMap":59},[63,1019,1020,1022],{"class":65,"line":66},[63,1021,126],{"class":81},[63,1023,1024],{"class":73}," src\u002Findex.ts\n",[10,1026,1027],{},"This file exports all library components:",[53,1029,1031],{"className":781,"code":1030,"filename":260,"language":783,"meta":59,"style":59},"export * from '.\u002FButton'\n",[48,1032,1033],{"__ignoreMap":59},[63,1034,1035,1037,1040,1043],{"class":65,"line":66},[63,1036,455],{"class":189},[63,1038,1039],{"class":69}," *",[63,1041,1042],{"class":189}," from",[63,1044,1045],{"class":73}," '.\u002FButton'\n",[10,1047,1048,1049,1052],{},"Create a new ",[48,1050,1051],{},"index.ts"," at the component level:",[53,1054,1056],{"className":55,"code":1055,"filename":1051,"language":58,"meta":59,"style":59},"touch src\u002FButton\u002Findex.ts\n",[48,1057,1058],{"__ignoreMap":59},[63,1059,1060,1062],{"class":65,"line":66},[63,1061,126],{"class":81},[63,1063,1064],{"class":73}," src\u002FButton\u002Findex.ts\n",[10,1066,1067],{},"This file serves as the public API, exposing selected elements to the user while keeping the internal structure hidden:",[53,1069,1071],{"className":781,"code":1070,"filename":260,"language":783,"meta":59,"style":59},"export {\n  default as Button,\n  type ButtonProps\n} from '.\u002FButton.vue'\n",[48,1072,1073,1079,1090,1098],{"__ignoreMap":59},[63,1074,1075,1077],{"class":65,"line":66},[63,1076,455],{"class":189},[63,1078,464],{"class":77},[63,1080,1081,1084,1087],{"class":65,"line":186},[63,1082,1083],{"class":189},"  default",[63,1085,1086],{"class":189}," as",[63,1088,1089],{"class":77}," Button,\n",[63,1091,1092,1095],{"class":65,"line":205},[63,1093,1094],{"class":189},"  type",[63,1096,1097],{"class":77}," ButtonProps\n",[63,1099,1100,1103,1105],{"class":65,"line":217},[63,1101,1102],{"class":77},"} ",[63,1104,199],{"class":189},[63,1106,1107],{"class":73}," '.\u002FButton.vue'\n",[10,1109,1110],{},"Finally, build the library:",[53,1112,1114],{"className":55,"code":1113,"filename":57,"language":58,"meta":59,"style":59},"pnpm run build\n",[48,1115,1116],{"__ignoreMap":59},[63,1117,1118,1120,1123],{"class":65,"line":66},[63,1119,82],{"class":81},[63,1121,1122],{"class":73}," run",[63,1124,1125],{"class":73}," build\n",[10,1127,1128,1129,1132,1133,595],{},"The library compiles under the ",[48,1130,1131],{},"dist"," directory as ",[48,1134,1135],{},"index.mjs",[40,1137,1139],{"id":1138},"exposing-the-components","Exposing the components",[10,1141,1142,1143,1146,1147,1150,1151,1154],{},"Our component library is built, but to be usable as an ",[14,1144,1145],{},"npm"," package, we need to define some fields in the ",[48,1148,1149],{},"package.json"," file. These fields provide crucial information to ",[14,1152,1153],{},"Node"," about how our package should be loaded:",[53,1156,1160],{"className":1157,"code":1158,"filename":1149,"language":1159,"meta":59,"style":59},"language-json shiki shiki-themes github-light github-light github-dark","{\n  \"exports\": {\n    \".\": {\n      \"import\": \".\u002Fdist\u002Findex.mjs\"\n    }\n  },\n  \"main\": \".\u002Fdist\u002Findex.mjs\"\n}\n","json",[48,1161,1162,1167,1175,1182,1193,1197,1201,1210],{"__ignoreMap":59},[63,1163,1164],{"class":65,"line":66},[63,1165,1166],{"class":77},"{\n",[63,1168,1169,1172],{"class":65,"line":186},[63,1170,1171],{"class":69},"  \"exports\"",[63,1173,1174],{"class":77},": {\n",[63,1176,1177,1180],{"class":65,"line":205},[63,1178,1179],{"class":69},"    \".\"",[63,1181,1174],{"class":77},[63,1183,1184,1187,1190],{"class":65,"line":217},[63,1185,1186],{"class":69},"      \"import\"",[63,1188,1189],{"class":77},": ",[63,1191,1192],{"class":73},"\".\u002Fdist\u002Findex.mjs\"\n",[63,1194,1195],{"class":65,"line":308},[63,1196,357],{"class":77},[63,1198,1199],{"class":65,"line":320},[63,1200,966],{"class":77},[63,1202,1203,1206,1208],{"class":65,"line":326},[63,1204,1205],{"class":69},"  \"main\"",[63,1207,1189],{"class":77},[63,1209,1192],{"class":73},[63,1211,1212],{"class":65,"line":332},[63,1213,499],{"class":77},[10,1215,1216,1217,1220,1221,1223,1224,724,1226,1228,1229,1232,1233,1235,1236,1238],{},"Simple, right? The ",[48,1218,1219],{},"exports"," field informs ",[14,1222,1153],{}," about the available imports for our package. In our case, we have only one import, the root of our package, and it is the ",[48,1225,1135],{},[48,1227,1131],{}," folder. The ",[48,1230,1231],{},"main"," field specifies the entry point of our package. Here, the entry point is the ",[48,1234,1135],{}," file located in the ",[48,1237,1131],{}," folder.",[226,1240,1241],{"color":999,"icon":229},[10,1242,1243,1244,1246,1247,1249,1250,1252,1253,1255,1256,595],{},"Since we have only one entry point, we could rely solely on the ",[48,1245,1231],{}," field. However, it is a good practice to define the ",[48,1248,1219],{}," field to ensure compatibility with future versions of ",[14,1251,1153],{}," and to prepare for the support of multiple entry points. The ",[48,1254,1219],{}," field is more modern and powerful than ",[48,1257,1231],{},[10,1259,1260,1261,1264],{},"In the next article, we will add ",[14,1262,1263],{},"type definitions"," to our component library to provide a better developer experience.",[1266,1267,1268],"style",{},"html pre.shiki code .sBjJW, html code.shiki .sBjJW{--shiki-light:#005CC5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}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 .snPdu, html code.shiki .snPdu{--shiki-light:#6F42C1;--shiki-default:#6F42C1;--shiki-dark:#B392F0}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 .sovSZ, html code.shiki .sovSZ{--shiki-light:#22863A;--shiki-default:#22863A;--shiki-dark:#85E89D}html pre.shiki code .s8jYJ, html code.shiki .s8jYJ{--shiki-light:#D73A49;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .sP4rz, html code.shiki .sP4rz{--shiki-light:#E36209;--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sPrNH, html code.shiki .sPrNH{--shiki-light:#B31D28;--shiki-light-font-style:italic;--shiki-default:#B31D28;--shiki-default-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic}",{"title":59,"searchDepth":186,"depth":186,"links":1270},[1271,1272,1273,1274],{"id":42,"depth":186,"text":43},{"id":139,"depth":186,"text":140},{"id":716,"depth":186,"text":717},{"id":1138,"depth":186,"text":1139},"e9f57d8c-a722-4fd7-b326-61af0ea9dbd4","2024-11-24","Creating a simple Vue.js button component using Tailwind CSS for styling and variants, along with step-by-step library build configuration using Vite.",null,{},"\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fbuilding-a-first-component-with-vuejs-and-tailwind-css","---\ncontentId: e9f57d8c-a722-4fd7-b326-61af0ea9dbd4\npart: 2\ntitle: Building a First Component with Vue.js and Tailwind CSS\ndescription: Creating a simple Vue.js button component using Tailwind CSS for styling and variants, along with step-by-step library build configuration using Vite.\ndate: 2024-11-24\nseriesSlug: the-complete-guide-to-building-a-vue-js-component-library\n---\n\nWith our **Vue.js** component library set up, it's time to build our first component: a simple button. This exercise will help us understand how to structure our components.\n\nWe'll use [**Tailwind CSS**](https:\u002F\u002Ftailwindcss.com\u002F) and [**Tailwind Variants**](https:\u002F\u002Fwww.tailwind-variants.org\u002F) for styling. Tailwind Variants helps organize Tailwind CSS classes in a structured way to create and combine variants.\n\n## Setting up the package\n\nNavigate to `packages\u002Fhuchet-vue` and install the necessary dependencies:\n\n```bash [terminal]\ncd packages\u002Fhuchet-vue && pnpm add -D vue vite\n```\n\nThen, create a `src` folder with the `Button\u002FButton.vue` component:\n\n```bash [Button\u002FButton.vue]\nmkdir -p src\u002FButton && touch src\u002FButton\u002FButton.vue\n```\n\nOpen the `Button.vue` file and let's start writing our component.\n\n## Writing the button component\n\nFor our example, we'll create a button with two variants: solid and outline. The solid variant will feature a background color, and the outline variant will include a border.\n\nTo ensure class non-conflict and simplify refactoring, maintainability, readability, and structure, we'll use Tailwind Variants. We'll organize our classes into an object, and Tailwind Variants will apply the correct classes based on props.\n\nAdd a `script` tag at the top of the `Button.vue` file:\n\n```vue [Button.vue]\n\u003Cscript lang=\"ts\">\nimport type { VariantProps } from 'tailwind-variants'\nimport { tv } from 'tailwind-variants'\n\u003C\u002Fscript>\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"primary\"}\nDo not add the `setup` attribute. This omission is intentional.\n::\n\nThe `tv` function is a helper for organizing classes. It accepts an object with `base` and `variants` keys. The `base` is a string of shared classes, whereas `variants` is a record with variant keys and class values.\n\n```vue [Example]\n\u003Cscript lang=\"ts\">\n\u002F\u002F ...\n\nconst button = tv({\n  base: 'border-2 px-2.5 py-1.5 text-sm font-semibold focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2',\n  variants: {\n    variant: {\n      solid: 'border-transparent bg-blue-500 text-white hover:bg-blue-600 active:bg-blue-700',\n      outline: 'border-blue-500 text-blue-500 hover:bg-blue-50 active:bg-blue-100',\n    }\n  }\n})\n\u003C\u002Fscript>\n```\n\nIn the `variants` key, you could also include more keys like `size` with `sm` and `md` variants.\n\nNext, extract the variants for use in our component props:\n\n```vue [Example]\n\u003Cscript lang=\"ts\">\n\u002F\u002F ...\n\ntype ButtonVariantProps = VariantProps\u003Ctypeof button>\n\nexport interface ButtonProps {\n  label?: string\n  variant?: ButtonVariantProps['variant']\n}\n\u003C\u002Fscript>\n```\n\nThen open a new `script` tag with the `setup` attribute:\n\n```vue [Example]\n\u003Cscript setup lang=\"ts\">\nwithDefaults(defineProps\u003CButtonProps>(), {\n  variant: 'solid',\n})\n\u003C\u002Fscript>\n```\n\nWe split the `script` tag into two parts to enable named exports. The `ButtonProps` interface is used in the `defineProps` function and is exported so developers can extend it to create a new component. This detail is crucial for building a robust **component library**.\n\nAdd the component's template:\n\n```vue [Example]\n\u003Ctemplate>\n  \u003Cbutton :class=\"button({ variant })\">\n    \u003Cslot>\n      {{ label }}\n    \u003C\u002Fslot>\n  \u003C\u002Fbutton>\n\u003C\u002Ftemplate>\n```\n\nOur component is ready to use:\n\n```html [Example]\n\u003CButton variant=\"outline\" label=\"Click me\" \u002F>\n```\n\nHowever, it's not usable until we build our component library.\n\n## Building the component library\n\nNext, we'll build the component library. Start by creating a `vite.config.ts` file in the `huchet-vue` package root:\n\n```bash [vite.config.ts]\ntouch vite.config.ts\n```\n\nThis configuration instructs **Vite** how to transpile our **Vue.js** components into JavaScript that can be used in other projects. By default, **Vite** caters to web applications, not libraries, so we'll adjust it for our needs.\n\nInstall the necessary plugin:\n\n```bash [terminal]\npnpm add -D @vitejs\u002Fplugin-vue\n```\n\nEdit the `vite.config.ts` file with the following configuration:\n\n```ts [vite.config.ts]\nimport Vue from '@vitejs\u002Fplugin-vue'\nimport { defineConfig } from 'vite'\n\nexport default defineConfig({\n  plugins: [Vue()],\n  build: {\n    lib: {\n      formats: ['es'],\n      name: 'huchet-vue',\n      fileName: (_, name) => `${name}.mjs`,\n      entry: {\n        index: resolve(__dirname, 'src\u002Findex.ts'),\n      },\n    },\n    rollupOptions: {\n      external: ['vue', 'tailwind-variants'],\n    },\n  },\n})\n```\n\nWe choose not to include Vue.js and Tailwind Variants in the final bundle for flexibility, allowing users to use their versions. This also avoid duplication in the final bundle if the user already has these dependencies.\n\nAdd them as peer dependencies:\n\n```bash [terminal]\npnpm add --save-peer vue tailwind-variants\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nA peer dependency isn't installed by the package but should be present in the user's project. This flexibility is especially useful when a package may operate in varied contexts.\n::\n\nCreate the `src\u002Findex.ts` file, as referenced in `vite.config.ts`:\n\n```bash [vite.config.ts]\ntouch src\u002Findex.ts\n```\n\nThis file exports all library components:\n\n```ts [Example]\nexport * from '.\u002FButton'\n```\n\nCreate a new `index.ts` at the component level:\n\n```bash [index.ts]\ntouch src\u002FButton\u002Findex.ts\n```\n\nThis file serves as the public API, exposing selected elements to the user while keeping the internal structure hidden:\n\n```ts [Example]\nexport {\n  default as Button,\n  type ButtonProps\n} from '.\u002FButton.vue'\n```\n\nFinally, build the library:\n\n```bash [terminal]\npnpm run build\n```\n\nThe library compiles under the `dist` directory as `index.mjs`.\n\n## Exposing the components\n\nOur component library is built, but to be usable as an **npm** package, we need to define some fields in the `package.json` file. These fields provide crucial information to **Node** about how our package should be loaded:\n\n```json [package.json]\n{\n  \"exports\": {\n    \".\": {\n      \"import\": \".\u002Fdist\u002Findex.mjs\"\n    }\n  },\n  \"main\": \".\u002Fdist\u002Findex.mjs\"\n}\n```\n\nSimple, right? The `exports` field informs **Node** about the available imports for our package. In our case, we have only one import, the root of our package, and it is the `index.mjs` file in the `dist` folder. The `main` field specifies the entry point of our package. Here, the entry point is the `index.mjs` file located in the `dist` folder.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nSince we have only one entry point, we could rely solely on the `main` field. However, it is a good practice to define the `exports` field to ensure compatibility with future versions of **Node** and to prepare for the support of multiple entry points. The `exports` field is more modern and powerful than `main`.\n::\n\nIn the next article, we will add **type definitions** to our component library to provide a better developer experience.\n",{"title":5,"description":1277},"the-complete-guide-to-building-a-vue-js-component-library",{"loc":1280},"series\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fbuilding-a-first-component-with-vuejs-and-tailwind-css","pFBz3M3j-TQ8_Je61JK0VQTBKahVc6CEXxCuBRoNoTk",{"overview":1288,"chapters":1484},{"id":1289,"title":1290,"body":1291,"contentId":1469,"date":1276,"description":1470,"extension":394,"github":1471,"meetTheInstructor":1473,"meta":1474,"navigation":287,"part":1278,"path":1475,"rawbody":1476,"robots":1278,"schemaOrg":1278,"seo":1477,"seriesSlug":1283,"sitemap":1478,"stem":1479,"subtitle":1480,"topics":1481,"__hash__":1483},"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":1292,"toc":1465},[1293,1296,1299,1311,1315,1318,1331,1335,1338,1452,1455,1459],[10,1294,1295],{},"Welcome! 👋",[10,1297,1298],{},"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,1300,1301,1302,1306,1307],{},"This series is somewhat of a sequel to the article ",[22,1303,1305],{"href":1304},"\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. ",[1308,1309,1310],"em",{},"You will learn how the most popular component libraries are constructed behind the scenes and how to create your own.",[1312,1313],"callout-read-more",{"id":1314},"f9754148-40bd-4df2-a144-f686e894b200",[10,1316,1317],{},"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,1319,1320,1321,1326,1327,595],{},"That's understandable. While ",[22,1322,1325],{"href":1323,"rel":1324},"https:\u002F\u002Fgithub.com\u002Funjs\u002Funbuild",[26],"unbuild"," is a powerful tool, it cannot match the flexibility, plugin ecosystem, and adoption of ",[22,1328,746],{"href":1329,"rel":1330},"https:\u002F\u002Fvite.dev\u002F",[26],[40,1332,1334],{"id":1333},"what-to-expect","What to expect",[10,1336,1337],{},"Throughout this series, we will address the following topics:",[1339,1340,1341,1354,1381,1399,1416,1422,1434],"ol",{},[1342,1343,1344,1347,1348,1353],"li",{},[14,1345,1346],{},"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 ",[22,1349,1352],{"href":1350,"rel":1351},"https:\u002F\u002Feslint.org\u002F",[26],"ESLint"," to ensure code consistency.",[1342,1355,1356,1358,1359,881,1363,1366,1367,1370,1371,30,1376,595],{},[14,1357,5],{},": We'll create our first component with ",[22,1360,16],{"href":1361,"rel":1362},"https:\u002F\u002Fvuejs.org\u002F",[26],[22,1364,29],{"href":24,"rel":1365},[26],", and ",[22,1368,37],{"href":33,"rel":1369},[26]," using the most advanced and powerful techniques employed in popular component libraries like ",[22,1372,1375],{"href":1373,"rel":1374},"https:\u002F\u002Fwww.radix-vue.com\u002F",[26],"Radix Vue",[22,1377,1380],{"href":1378,"rel":1379},"https:\u002F\u002Fui.nuxt.com\u002F",[26],"Nuxt UI",[1342,1382,1383,1386,1387,1392,1393,1398],{},[14,1384,1385],{},"A Better Development Experience with TypeScript and TSConfig",": We'll enhance our development experience by adding ",[22,1388,1391],{"href":1389,"rel":1390},"https:\u002F\u002Fwww.typescriptlang.org\u002F",[26],"TypeScript"," to our component library and configuring ",[22,1394,1397],{"href":1395,"rel":1396},"https:\u002F\u002Fwww.typescriptlang.org\u002Ftsconfig",[26],"TSConfig"," to ensure that our components are typed correctly and that we can take full advantage of TypeScript's features.",[1342,1400,1401,1404,1405,30,1410,1415],{},[14,1402,1403],{},"Automatic Component Testing with Vitest and Testing Library",": We'll write tests for our components using ",[22,1406,1409],{"href":1407,"rel":1408},"https:\u002F\u002Fvitest.dev\u002Fguide\u002F",[26],"Vitest",[22,1411,1414],{"href":1412,"rel":1413},"https:\u002F\u002Ftesting-library.com\u002F",[26],"Testing Library"," to ensure that our components function as expected. This is crucial for a professional component library that remains reliable over time.",[1342,1417,1418,1421],{},[14,1419,1420],{},"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.",[1342,1423,1424,1427,1428,1433],{},[14,1425,1426],{},"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 ",[22,1429,1432],{"href":1430,"rel":1431},"https:\u002F\u002Fhistoire.dev\u002F",[26],"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.",[1342,1435,1436,1439,1440,1445,1446,1451],{},[14,1437,1438],{},"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 ",[22,1441,1444],{"href":1442,"rel":1443},"https:\u002F\u002Fgithub.com\u002Funplugin\u002Funplugin-vue-components",[26],"Unplugin Vue Components"," and a ",[22,1447,1450],{"href":1448,"rel":1449},"https:\u002F\u002Fnuxt.com\u002Fdocs\u002Fguide\u002Fgoing-further\u002Fmodules",[26],"Nuxt module"," to utilize our components in a Nuxt application.",[10,1453,1454],{},"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? 😎",[40,1456,1458],{"id":1457},"chapters","Chapters",[1460,1461],"series-chapters-list",{"className":1462},[1463,1464],"mx-auto","max-w-5xl",{"title":59,"searchDepth":186,"depth":186,"links":1466},[1467,1468],{"id":1333,"depth":186,"text":1334},{"id":1457,"depth":186,"text":1458},"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":727,"repository":1472},"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":1290,"description":1470},{"loc":1475},"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.",[161,1482,594],"vite","2VSSnBlkuSLlt05n9MySLBFt6vBkgd7691eX-TK2cTs",[1485,1489,1490,1494,1498,1502,1506],{"contentId":1486,"title":1346,"description":1487,"path":1488,"part":66,"github":1278,"topics":1278},"1f6cf4af-8637-458d-93f8-52ac60dd8f87","Start your monorepo journey! Learn how to set up a linter and formatter for streamlined coding and organizing your project.","\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fgetting-started-with-monorepo-linter-and-formatter",{"contentId":1275,"title":5,"description":1277,"path":1280,"part":186,"github":1278,"topics":1278},{"contentId":1491,"title":1385,"description":1492,"path":1493,"part":205,"github":1278,"topics":1278},"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":1495,"title":1403,"description":1496,"path":1497,"part":217,"github":1278,"topics":1278},"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":1499,"title":1420,"description":1500,"path":1501,"part":308,"github":1278,"topics":1278},"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":1503,"title":1426,"description":1504,"path":1505,"part":320,"github":1278,"topics":1278},"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":1507,"title":1438,"description":1508,"path":1509,"part":326,"github":1278,"topics":1278},"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",1795016694475]