[{"data":1,"prerenderedAt":2758},["ShallowReactive",2],{"series-\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fenhancing-integration-with-unplugin-and-nuxt-module":3,"series-context-\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library":2533},{"id":4,"title":5,"body":6,"contentId":2520,"date":2521,"description":2522,"extension":2523,"github":2524,"meetTheInstructor":2524,"meta":2525,"navigation":125,"part":301,"path":2526,"rawbody":2527,"robots":2524,"schemaOrg":2524,"seo":2528,"seriesSlug":2529,"sitemap":2530,"stem":2531,"subtitle":2524,"topics":2524,"__hash__":2532},"series\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fenhancing-integration-with-unplugin-and-nuxt-module.md","Enhancing Integration with Unplugin and Nuxt Module",{"type":7,"value":8,"toc":2510},"minimark",[9,18,44,47,52,58,66,69,166,172,175,181,221,224,308,311,324,329,340,355,358,391,405,417,420,520,523,534,541,568,575,910,915,1029,1035,1156,1161,1165,1168,1173,1187,1195,1210,1222,1361,1373,1392,1400,1411,1496,1502,1506,1509,1513,1522,1534,1537,1571,1574,1947,1950,1953,1966,1974,2100,2109,2239,2243,2246,2251,2270,2290,2295,2316,2325,2341,2349,2428,2437,2445,2480,2485,2497,2500,2506],[10,11,12,13,17],"p",{},"Having a robust component library is a great start, but integrating it into the ",[14,15,16],"strong",{},"Vue.js ecosystem"," takes it to another level. In this ecosystem, two main tools stand out:",[19,20,21,34],"ol",{},[22,23,24,33],"li",{},[25,26,30],"a",{"href":27,"rel":28},"https:\u002F\u002Fgithub.com\u002Funplugin\u002Funplugin-vue-components",[29],"nofollow",[14,31,32],{},"Unplugin Vue Components",": A bundler plugin for on-demand components that are auto-imported, fully typed, and tree-shakable.",[22,35,36,43],{},[25,37,40],{"href":38,"rel":39},"https:\u002F\u002Fnuxt.com",[29],[14,41,42],{},"Nuxt",": An open-source framework based on Vue.js that simplifies and empowers web development.",[10,45,46],{},"Although our component library can function without integration into these tools, I'm firmly convinced that integration will enhance its power and ease of use. I'm devoted to providing the best developer experience possible, and I'm sure you will find it invaluable.",[48,49,51],"h2",{"id":50},"unplugin-vue-component-resolver","Unplugin Vue component resolver",[10,53,54,55,57],{},"Before building the resolver, it's essential to understand how ",[14,56,32],{}," works. This will clarify what a resolver does and its functionality.",[59,60,63],"callout",{"color":61,"icon":62},"success","i-ph-lightbulb-duotone",[10,64,65],{},"If you have any questions, please comment below, and I'll be happy to assist.",[10,67,68],{},"Consider this component:",[70,71,77],"pre",{"className":72,"code":73,"filename":74,"language":75,"meta":76,"style":76},"language-vue shiki shiki-themes github-light github-light github-dark","\u003Cscript lang=\"ts\" setup>\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003CUButton label=\"Click me\" \u002F>\n\u003C\u002Ftemplate>\n","Example","vue","",[78,79,80,110,120,127,137,157],"code",{"__ignoreMap":76},[81,82,85,89,93,97,100,104,107],"span",{"class":83,"line":84},"line",1,[81,86,88],{"class":87},"sxrX7","\u003C",[81,90,92],{"class":91},"sovSZ","script",[81,94,96],{"class":95},"snPdu"," lang",[81,98,99],{"class":87},"=",[81,101,103],{"class":102},"sIIMD","\"ts\"",[81,105,106],{"class":95}," setup",[81,108,109],{"class":87},">\n",[81,111,113,116,118],{"class":83,"line":112},2,[81,114,115],{"class":87},"\u003C\u002F",[81,117,92],{"class":91},[81,119,109],{"class":87},[81,121,123],{"class":83,"line":122},3,[81,124,126],{"emptyLinePlaceholder":125},true,"\n",[81,128,130,132,135],{"class":83,"line":129},4,[81,131,88],{"class":87},[81,133,134],{"class":91},"template",[81,136,109],{"class":87},[81,138,140,143,146,149,151,154],{"class":83,"line":139},5,[81,141,142],{"class":87},"  \u003C",[81,144,145],{"class":91},"UButton",[81,147,148],{"class":95}," label",[81,150,99],{"class":87},[81,152,153],{"class":102},"\"Click me\"",[81,155,156],{"class":87}," \u002F>\n",[81,158,160,162,164],{"class":83,"line":159},6,[81,161,115],{"class":87},[81,163,134],{"class":91},[81,165,109],{"class":87},[10,167,168,169,171],{},"Notice that there's no import statement for the ",[78,170,145],{}," component. Unplugin Vue Components scans the template and identifies non-standard HTML tags to find them in its component list. This list can be manually fed or automatically populated using a resolver.",[10,173,174],{},"A resolver is a function that receives a component name and returns its import path if it matches the resolver's internal list. This allows selective auto-import of components or adding prefixes to component names.",[10,176,177,178,180],{},"In our example, a resolver might resolve the ",[78,179,145],{}," component as:",[70,182,186],{"className":183,"code":184,"filename":74,"language":185,"meta":76,"style":76},"language-ts shiki shiki-themes github-light github-light github-dark","return {\n  name: 'Button',\n  from: '@nuxt\u002Fui'\n}\n","ts",[78,187,188,197,208,216],{"__ignoreMap":76},[81,189,190,194],{"class":83,"line":84},[81,191,193],{"class":192},"s8jYJ","return",[81,195,196],{"class":87}," {\n",[81,198,199,202,205],{"class":83,"line":112},[81,200,201],{"class":87},"  name: ",[81,203,204],{"class":102},"'Button'",[81,206,207],{"class":87},",\n",[81,209,210,213],{"class":83,"line":122},[81,211,212],{"class":87},"  from: ",[81,214,215],{"class":102},"'@nuxt\u002Fui'\n",[81,217,218],{"class":83,"line":129},[81,219,220],{"class":87},"}\n",[10,222,223],{},"Unplugin Vue Components would transform the component by injecting the import statement:",[70,225,227],{"className":72,"code":226,"filename":74,"language":75,"meta":76,"style":76},"\u003Cscript lang=\"ts\" setup>\nimport { Button as UButton } from '@nuxt\u002Fui'\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003CUButton label=\"Click me\" \u002F>\n\u003C\u002Ftemplate>\n",[78,228,229,245,265,273,277,285,299],{"__ignoreMap":76},[81,230,231,233,235,237,239,241,243],{"class":83,"line":84},[81,232,88],{"class":87},[81,234,92],{"class":91},[81,236,96],{"class":95},[81,238,99],{"class":87},[81,240,103],{"class":102},[81,242,106],{"class":95},[81,244,109],{"class":87},[81,246,247,250,253,256,259,262],{"class":83,"line":112},[81,248,249],{"class":192},"import",[81,251,252],{"class":87}," { Button ",[81,254,255],{"class":192},"as",[81,257,258],{"class":87}," UButton } ",[81,260,261],{"class":192},"from",[81,263,264],{"class":102}," '@nuxt\u002Fui'\n",[81,266,267,269,271],{"class":83,"line":122},[81,268,115],{"class":87},[81,270,92],{"class":91},[81,272,109],{"class":87},[81,274,275],{"class":83,"line":129},[81,276,126],{"emptyLinePlaceholder":125},[81,278,279,281,283],{"class":83,"line":139},[81,280,88],{"class":87},[81,282,134],{"class":91},[81,284,109],{"class":87},[81,286,287,289,291,293,295,297],{"class":83,"line":159},[81,288,142],{"class":87},[81,290,145],{"class":91},[81,292,148],{"class":95},[81,294,99],{"class":87},[81,296,153],{"class":102},[81,298,156],{"class":87},[81,300,302,304,306],{"class":83,"line":301},7,[81,303,115],{"class":87},[81,305,134],{"class":91},[81,307,109],{"class":87},[10,309,310],{},"Simple, right? Now, let's build our resolver.",[59,312,315],{"color":313,"icon":314},"info","i-ph-info-duotone",[10,316,317,318,323],{},"To deepen your understanding of Vite, try the ",[25,319,322],{"href":320,"rel":321},"https:\u002F\u002Fgithub.com\u002Fantfu-collective\u002Fvite-plugin-inspect",[29],"vite-plugin-inspector",", which lets you inspect modifications made by each plugin.",[325,326,328],"h3",{"id":327},"building-the-resolver","Building the resolver",[10,330,331,332,335,336,339],{},"First, gather all your library components in a ",[78,333,334],{},"src\u002Fcomponents.ts"," file within the ",[78,337,338],{},"packages\u002Fhuchet-vue"," folder:",[70,341,345],{"className":342,"code":343,"filename":334,"language":344,"meta":76,"style":76},"language-bash shiki shiki-themes github-light github-light github-dark","touch src\u002Fcomponents.ts\n","bash",[78,346,347],{"__ignoreMap":76},[81,348,349,352],{"class":83,"line":84},[81,350,351],{"class":95},"touch",[81,353,354],{"class":102}," src\u002Fcomponents.ts\n",[10,356,357],{},"Then export an array of all components:",[70,359,361],{"className":183,"code":360,"filename":74,"language":185,"meta":76,"style":76},"export const components = [\n  'Button'\n]\n",[78,362,363,381,386],{"__ignoreMap":76},[81,364,365,368,371,375,378],{"class":83,"line":84},[81,366,367],{"class":192},"export",[81,369,370],{"class":192}," const",[81,372,374],{"class":373},"sBjJW"," components",[81,376,377],{"class":192}," =",[81,379,380],{"class":87}," [\n",[81,382,383],{"class":83,"line":112},[81,384,385],{"class":102},"  'Button'\n",[81,387,388],{"class":83,"line":122},[81,389,390],{"class":87},"]\n",[10,392,393,394,397,398,401,402,404],{},"To ensure updates, create a test that verifies the exported components match those in the ",[78,395,396],{},"components"," folder. Create a ",[78,399,400],{},"src\u002Findex.test.ts"," file in ",[78,403,338],{},":",[70,406,408],{"className":342,"code":407,"filename":400,"language":344,"meta":76,"style":76},"touch src\u002Findex.test.ts\n",[78,409,410],{"__ignoreMap":76},[81,411,412,414],{"class":83,"line":84},[81,413,351],{"class":95},[81,415,416],{"class":102}," src\u002Findex.test.ts\n",[10,418,419],{},"Add this test to verify component exports:",[70,421,423],{"className":183,"code":422,"filename":74,"language":185,"meta":76,"style":76},"import { expect, it } from 'vitest'\nimport { components } from '.\u002Fcomponents'\nimport * as Huchet from '.\u002Findex'\n\nit('should expose the correct components', () => {\n  expect(Object.keys(Huchet)).toEqual(Object.values(components))\n})\n",[78,424,425,437,449,467,471,490,515],{"__ignoreMap":76},[81,426,427,429,432,434],{"class":83,"line":84},[81,428,249],{"class":192},[81,430,431],{"class":87}," { expect, it } ",[81,433,261],{"class":192},[81,435,436],{"class":102}," 'vitest'\n",[81,438,439,441,444,446],{"class":83,"line":112},[81,440,249],{"class":192},[81,442,443],{"class":87}," { components } ",[81,445,261],{"class":192},[81,447,448],{"class":102}," '.\u002Fcomponents'\n",[81,450,451,453,456,459,462,464],{"class":83,"line":122},[81,452,249],{"class":192},[81,454,455],{"class":373}," *",[81,457,458],{"class":192}," as",[81,460,461],{"class":87}," Huchet ",[81,463,261],{"class":192},[81,465,466],{"class":102}," '.\u002Findex'\n",[81,468,469],{"class":83,"line":129},[81,470,126],{"emptyLinePlaceholder":125},[81,472,473,476,479,482,485,488],{"class":83,"line":139},[81,474,475],{"class":95},"it",[81,477,478],{"class":87},"(",[81,480,481],{"class":102},"'should expose the correct components'",[81,483,484],{"class":87},", () ",[81,486,487],{"class":192},"=>",[81,489,196],{"class":87},[81,491,492,495,498,501,504,507,509,512],{"class":83,"line":159},[81,493,494],{"class":95},"  expect",[81,496,497],{"class":87},"(Object.",[81,499,500],{"class":95},"keys",[81,502,503],{"class":87},"(Huchet)).",[81,505,506],{"class":95},"toEqual",[81,508,497],{"class":87},[81,510,511],{"class":95},"values",[81,513,514],{"class":87},"(components))\n",[81,516,517],{"class":83,"line":301},[81,518,519],{"class":87},"})\n",[10,521,522],{},"This test prevents missed updates when components change.",[59,524,525],{"color":313,"icon":314},[10,526,527,528,533],{},"Inspired by ",[25,529,532],{"href":530,"rel":531},"https:\u002F\u002Fgithub.com\u002Funovue\u002Fradix-vue\u002Fblob\u002Fmain\u002Fpackages\u002Fradix-vue\u002Fsrc\u002Findex.test.ts",[29],"Radix Vue",".",[10,535,536,537,540],{},"Next, create a ",[78,538,539],{},"src\u002Fresolver.ts"," for the Unplugin Vue Components resolver and install it as a dev dependency:",[70,542,544],{"className":342,"code":543,"filename":539,"language":344,"meta":76,"style":76},"touch src\u002Fresolver.ts && pnpm add -D unplugin-vue-components\n",[78,545,546],{"__ignoreMap":76},[81,547,548,550,553,556,559,562,565],{"class":83,"line":84},[81,549,351],{"class":95},[81,551,552],{"class":102}," src\u002Fresolver.ts",[81,554,555],{"class":87}," && ",[81,557,558],{"class":95},"pnpm",[81,560,561],{"class":102}," add",[81,563,564],{"class":373}," -D",[81,566,567],{"class":102}," unplugin-vue-components\n",[10,569,570,571,574],{},"The resolver function initiates in ",[78,572,573],{},"vite.config.ts",", allowing developers to pass options like a prefix for component names. It resolves component names and returns import paths if they match:",[70,576,578],{"className":183,"code":577,"filename":573,"language":185,"meta":76,"style":76},"import type { ComponentResolver } from 'unplugin-vue-components'\nimport { components } from '.\u002Fcomponents'\n\nexport interface ResolverOptions {\n  \u002F**\n   * prefix for components used in templates\n   *\n   * @defaultValue \"\"\n   *\u002F\n  prefix?: string\n}\n\nexport default function (options: ResolverOptions = {}): ComponentResolver {\n  const { prefix = '' } = options\n\n  return {\n    type: 'component',\n    resolve: (name: string) => {\n      if (name.toLowerCase().startsWith(prefix.toLowerCase())) {\n        const componentName = name.substring(prefix.length)\n        if (components.includes(componentName)) {\n          return {\n            name: componentName,\n            from: '@barbapapazes\u002Fhuchet-vue',\n          }\n        }\n      }\n    },\n  }\n}\n",[78,579,580,595,605,609,621,627,632,637,649,655,668,673,678,711,736,741,749,760,784,810,835,850,858,864,875,881,887,893,899,905],{"__ignoreMap":76},[81,581,582,584,587,590,592],{"class":83,"line":84},[81,583,249],{"class":192},[81,585,586],{"class":192}," type",[81,588,589],{"class":87}," { ComponentResolver } ",[81,591,261],{"class":192},[81,593,594],{"class":102}," 'unplugin-vue-components'\n",[81,596,597,599,601,603],{"class":83,"line":112},[81,598,249],{"class":192},[81,600,443],{"class":87},[81,602,261],{"class":192},[81,604,448],{"class":102},[81,606,607],{"class":83,"line":122},[81,608,126],{"emptyLinePlaceholder":125},[81,610,611,613,616,619],{"class":83,"line":129},[81,612,367],{"class":192},[81,614,615],{"class":192}," interface",[81,617,618],{"class":95}," ResolverOptions",[81,620,196],{"class":87},[81,622,623],{"class":83,"line":139},[81,624,626],{"class":625},"sCsY4","  \u002F**\n",[81,628,629],{"class":83,"line":159},[81,630,631],{"class":625},"   * prefix for components used in templates\n",[81,633,634],{"class":83,"line":301},[81,635,636],{"class":625},"   *\n",[81,638,640,643,646],{"class":83,"line":639},8,[81,641,642],{"class":625},"   * ",[81,644,645],{"class":192},"@defaultValue",[81,647,648],{"class":625}," \"\"\n",[81,650,652],{"class":83,"line":651},9,[81,653,654],{"class":625},"   *\u002F\n",[81,656,658,662,665],{"class":83,"line":657},10,[81,659,661],{"class":660},"sP4rz","  prefix",[81,663,664],{"class":192},"?:",[81,666,667],{"class":373}," string\n",[81,669,671],{"class":83,"line":670},11,[81,672,220],{"class":87},[81,674,676],{"class":83,"line":675},12,[81,677,126],{"emptyLinePlaceholder":125},[81,679,681,683,686,689,692,695,697,699,701,704,706,709],{"class":83,"line":680},13,[81,682,367],{"class":192},[81,684,685],{"class":192}," default",[81,687,688],{"class":192}," function",[81,690,691],{"class":87}," (",[81,693,694],{"class":660},"options",[81,696,404],{"class":192},[81,698,618],{"class":95},[81,700,377],{"class":192},[81,702,703],{"class":87}," {})",[81,705,404],{"class":192},[81,707,708],{"class":95}," ComponentResolver",[81,710,196],{"class":87},[81,712,714,717,720,723,725,728,731,733],{"class":83,"line":713},14,[81,715,716],{"class":192},"  const",[81,718,719],{"class":87}," { ",[81,721,722],{"class":373},"prefix",[81,724,377],{"class":192},[81,726,727],{"class":102}," ''",[81,729,730],{"class":87}," } ",[81,732,99],{"class":192},[81,734,735],{"class":87}," options\n",[81,737,739],{"class":83,"line":738},15,[81,740,126],{"emptyLinePlaceholder":125},[81,742,744,747],{"class":83,"line":743},16,[81,745,746],{"class":192},"  return",[81,748,196],{"class":87},[81,750,752,755,758],{"class":83,"line":751},17,[81,753,754],{"class":87},"    type: ",[81,756,757],{"class":102},"'component'",[81,759,207],{"class":87},[81,761,763,766,769,772,774,777,780,782],{"class":83,"line":762},18,[81,764,765],{"class":95},"    resolve",[81,767,768],{"class":87},": (",[81,770,771],{"class":660},"name",[81,773,404],{"class":192},[81,775,776],{"class":373}," string",[81,778,779],{"class":87},") ",[81,781,487],{"class":192},[81,783,196],{"class":87},[81,785,787,790,793,796,799,802,805,807],{"class":83,"line":786},19,[81,788,789],{"class":192},"      if",[81,791,792],{"class":87}," (name.",[81,794,795],{"class":95},"toLowerCase",[81,797,798],{"class":87},"().",[81,800,801],{"class":95},"startsWith",[81,803,804],{"class":87},"(prefix.",[81,806,795],{"class":95},[81,808,809],{"class":87},"())) {\n",[81,811,813,816,819,821,824,827,829,832],{"class":83,"line":812},20,[81,814,815],{"class":192},"        const",[81,817,818],{"class":373}," componentName",[81,820,377],{"class":192},[81,822,823],{"class":87}," name.",[81,825,826],{"class":95},"substring",[81,828,804],{"class":87},[81,830,831],{"class":373},"length",[81,833,834],{"class":87},")\n",[81,836,838,841,844,847],{"class":83,"line":837},21,[81,839,840],{"class":192},"        if",[81,842,843],{"class":87}," (components.",[81,845,846],{"class":95},"includes",[81,848,849],{"class":87},"(componentName)) {\n",[81,851,853,856],{"class":83,"line":852},22,[81,854,855],{"class":192},"          return",[81,857,196],{"class":87},[81,859,861],{"class":83,"line":860},23,[81,862,863],{"class":87},"            name: componentName,\n",[81,865,867,870,873],{"class":83,"line":866},24,[81,868,869],{"class":87},"            from: ",[81,871,872],{"class":102},"'@barbapapazes\u002Fhuchet-vue'",[81,874,207],{"class":87},[81,876,878],{"class":83,"line":877},25,[81,879,880],{"class":87},"          }\n",[81,882,884],{"class":83,"line":883},26,[81,885,886],{"class":87},"        }\n",[81,888,890],{"class":83,"line":889},27,[81,891,892],{"class":87},"      }\n",[81,894,896],{"class":83,"line":895},28,[81,897,898],{"class":87},"    },\n",[81,900,902],{"class":83,"line":901},29,[81,903,904],{"class":87},"  }\n",[81,906,908],{"class":83,"line":907},30,[81,909,220],{"class":87},[10,911,912,913,404],{},"To ensure the resolver is built, add it as an entry point in ",[78,914,573],{},[70,916,919],{"className":917,"code":918,"filename":573,"language":185,"meta":76,"style":76},"language-ts shiki shiki-themes github-light github-light github-dark has-diff","import { resolve } from 'node:path'\nimport { defineConfig } from 'vite'\n\nexport default defineConfig({\n  build: {\n    lib: {\n      entry: {\n        index: resolve(__dirname, 'src\u002Findex.ts'),\n        resolver: resolve(__dirname, 'src\u002Fresolver.ts'), \u002F\u002F [!code ++]\n      },\n    },\n  },\n})\n",[78,920,921,933,945,949,961,966,971,976,993,1011,1016,1020,1025],{"__ignoreMap":76},[81,922,923,925,928,930],{"class":83,"line":84},[81,924,249],{"class":192},[81,926,927],{"class":87}," { resolve } ",[81,929,261],{"class":192},[81,931,932],{"class":102}," 'node:path'\n",[81,934,935,937,940,942],{"class":83,"line":112},[81,936,249],{"class":192},[81,938,939],{"class":87}," { defineConfig } ",[81,941,261],{"class":192},[81,943,944],{"class":102}," 'vite'\n",[81,946,947],{"class":83,"line":122},[81,948,126],{"emptyLinePlaceholder":125},[81,950,951,953,955,958],{"class":83,"line":129},[81,952,367],{"class":192},[81,954,685],{"class":192},[81,956,957],{"class":95}," defineConfig",[81,959,960],{"class":87},"({\n",[81,962,963],{"class":83,"line":139},[81,964,965],{"class":87},"  build: {\n",[81,967,968],{"class":83,"line":159},[81,969,970],{"class":87},"    lib: {\n",[81,972,973],{"class":83,"line":301},[81,974,975],{"class":87},"      entry: {\n",[81,977,978,981,984,987,990],{"class":83,"line":639},[81,979,980],{"class":87},"        index: ",[81,982,983],{"class":95},"resolve",[81,985,986],{"class":87},"(__dirname, ",[81,988,989],{"class":102},"'src\u002Findex.ts'",[81,991,992],{"class":87},"),\n",[81,994,998,1001,1003,1005,1008],{"class":995,"line":651},[83,996,997],"diff","add",[81,999,1000],{"class":87},"        resolver: ",[81,1002,983],{"class":95},[81,1004,986],{"class":87},[81,1006,1007],{"class":102},"'src\u002Fresolver.ts'",[81,1009,1010],{"class":87},"), ",[81,1012,1013],{"class":83,"line":657},[81,1014,1015],{"class":87},"      },\n",[81,1017,1018],{"class":83,"line":670},[81,1019,898],{"class":87},[81,1021,1022],{"class":83,"line":675},[81,1023,1024],{"class":87},"  },\n",[81,1026,1027],{"class":83,"line":680},[81,1028,519],{"class":87},[10,1030,1031,1032,404],{},"Finally, export the resolver in ",[78,1033,1034],{},"package.json",[70,1036,1040],{"className":1037,"code":1038,"filename":1034,"language":1039,"meta":76,"style":76},"language-json shiki shiki-themes github-light github-light github-dark has-diff","{\n  \"exports\": {\n    \".\": {\n      \"types\": \".\u002Fdist\u002Findex.d.ts\",\n      \"import\": \".\u002Fdist\u002Findex.mjs\"\n    },\n    \".\u002Fresolver\": { \u002F\u002F [!code ++]\n      \"types\": \".\u002Fdist\u002Fresolver.d.ts\", \u002F\u002F [!code ++]\n      \"import\": \".\u002Fdist\u002Fresolver.mjs\" \u002F\u002F [!code ++]\n    }\n  },\n  \"main\": \".\u002Fdist\u002Findex.mjs\",\n  \"types\": \"dist\u002Findex.d.ts\"\n}\n","json",[78,1041,1042,1047,1055,1062,1075,1085,1089,1098,1111,1121,1126,1130,1142,1152],{"__ignoreMap":76},[81,1043,1044],{"class":83,"line":84},[81,1045,1046],{"class":87},"{\n",[81,1048,1049,1052],{"class":83,"line":112},[81,1050,1051],{"class":373},"  \"exports\"",[81,1053,1054],{"class":87},": {\n",[81,1056,1057,1060],{"class":83,"line":122},[81,1058,1059],{"class":373},"    \".\"",[81,1061,1054],{"class":87},[81,1063,1064,1067,1070,1073],{"class":83,"line":129},[81,1065,1066],{"class":373},"      \"types\"",[81,1068,1069],{"class":87},": ",[81,1071,1072],{"class":102},"\".\u002Fdist\u002Findex.d.ts\"",[81,1074,207],{"class":87},[81,1076,1077,1080,1082],{"class":83,"line":139},[81,1078,1079],{"class":373},"      \"import\"",[81,1081,1069],{"class":87},[81,1083,1084],{"class":102},"\".\u002Fdist\u002Findex.mjs\"\n",[81,1086,1087],{"class":83,"line":159},[81,1088,898],{"class":87},[81,1090,1092,1095],{"class":1091,"line":301},[83,996,997],[81,1093,1094],{"class":373},"    \".\u002Fresolver\"",[81,1096,1097],{"class":87},": { ",[81,1099,1101,1103,1105,1108],{"class":1100,"line":639},[83,996,997],[81,1102,1066],{"class":373},[81,1104,1069],{"class":87},[81,1106,1107],{"class":102},"\".\u002Fdist\u002Fresolver.d.ts\"",[81,1109,1110],{"class":87},", ",[81,1112,1114,1116,1118],{"class":1113,"line":651},[83,996,997],[81,1115,1079],{"class":373},[81,1117,1069],{"class":87},[81,1119,1120],{"class":102},"\".\u002Fdist\u002Fresolver.mjs\"",[81,1122,1123],{"class":83,"line":657},[81,1124,1125],{"class":87},"    }\n",[81,1127,1128],{"class":83,"line":670},[81,1129,1024],{"class":87},[81,1131,1132,1135,1137,1140],{"class":83,"line":675},[81,1133,1134],{"class":373},"  \"main\"",[81,1136,1069],{"class":87},[81,1138,1139],{"class":102},"\".\u002Fdist\u002Findex.mjs\"",[81,1141,207],{"class":87},[81,1143,1144,1147,1149],{"class":83,"line":680},[81,1145,1146],{"class":373},"  \"types\"",[81,1148,1069],{"class":87},[81,1150,1151],{"class":102},"\"dist\u002Findex.d.ts\"\n",[81,1153,1154],{"class":83,"line":713},[81,1155,220],{"class":87},[59,1157,1158],{"color":313,"icon":314},[10,1159,1160],{},"Rebuild the project to ensure the new entry point is accessible.",[325,1162,1164],{"id":1163},"using-the-resolver","Using the resolver",[10,1166,1167],{},"With the resolver ready, let's test it in our playground project:",[19,1169,1170],{},[22,1171,1172],{},"Navigate to the playground folder:",[70,1174,1177],{"className":342,"code":1175,"filename":1176,"language":344,"meta":76,"style":76},"cd ..\u002F..\u002Fplayground\u002Fvue\n","terminal",[78,1178,1179],{"__ignoreMap":76},[81,1180,1181,1184],{"class":83,"line":84},[81,1182,1183],{"class":373},"cd",[81,1185,1186],{"class":102}," ..\u002F..\u002Fplayground\u002Fvue\n",[19,1188,1189],{"start":112},[22,1190,1191,1192,404],{},"Install ",[78,1193,1194],{},"unplugin-vue-components",[70,1196,1198],{"className":342,"code":1197,"filename":1176,"language":344,"meta":76,"style":76},"pnpm add -D unplugin-vue-components\n",[78,1199,1200],{"__ignoreMap":76},[81,1201,1202,1204,1206,1208],{"class":83,"line":84},[81,1203,558],{"class":95},[81,1205,561],{"class":102},[81,1207,564],{"class":373},[81,1209,567],{"class":102},[19,1211,1212],{"start":122},[22,1213,1214,1215,1217,1218,1221],{},"Update ",[78,1216,573],{}," to use the resolver with a ",[78,1219,1220],{},"U"," prefix:",[70,1223,1225],{"className":183,"code":1224,"filename":573,"language":185,"meta":76,"style":76},"import HuchetVueResolver from '@barbapapazes\u002Fhuchet-vue\u002Fresolver'\nimport Vue from '@vitejs\u002Fplugin-vue'\nimport Components from 'unplugin-vue-components\u002Fvite'\nimport { defineConfig } from 'vite'\n\nexport default defineConfig({\n  plugins: [\n    Vue(),\n    Components({\n      dts: true,\n      resolvers: [\n        HuchetVueResolver({\n          prefix: 'U'\n        }),\n      ],\n    })\n  ],\n})\n",[78,1226,1227,1239,1251,1263,1273,1277,1287,1292,1300,1307,1317,1322,1329,1337,1342,1347,1352,1357],{"__ignoreMap":76},[81,1228,1229,1231,1234,1236],{"class":83,"line":84},[81,1230,249],{"class":192},[81,1232,1233],{"class":87}," HuchetVueResolver ",[81,1235,261],{"class":192},[81,1237,1238],{"class":102}," '@barbapapazes\u002Fhuchet-vue\u002Fresolver'\n",[81,1240,1241,1243,1246,1248],{"class":83,"line":112},[81,1242,249],{"class":192},[81,1244,1245],{"class":87}," Vue ",[81,1247,261],{"class":192},[81,1249,1250],{"class":102}," '@vitejs\u002Fplugin-vue'\n",[81,1252,1253,1255,1258,1260],{"class":83,"line":122},[81,1254,249],{"class":192},[81,1256,1257],{"class":87}," Components ",[81,1259,261],{"class":192},[81,1261,1262],{"class":102}," 'unplugin-vue-components\u002Fvite'\n",[81,1264,1265,1267,1269,1271],{"class":83,"line":129},[81,1266,249],{"class":192},[81,1268,939],{"class":87},[81,1270,261],{"class":192},[81,1272,944],{"class":102},[81,1274,1275],{"class":83,"line":139},[81,1276,126],{"emptyLinePlaceholder":125},[81,1278,1279,1281,1283,1285],{"class":83,"line":159},[81,1280,367],{"class":192},[81,1282,685],{"class":192},[81,1284,957],{"class":95},[81,1286,960],{"class":87},[81,1288,1289],{"class":83,"line":301},[81,1290,1291],{"class":87},"  plugins: [\n",[81,1293,1294,1297],{"class":83,"line":639},[81,1295,1296],{"class":95},"    Vue",[81,1298,1299],{"class":87},"(),\n",[81,1301,1302,1305],{"class":83,"line":651},[81,1303,1304],{"class":95},"    Components",[81,1306,960],{"class":87},[81,1308,1309,1312,1315],{"class":83,"line":657},[81,1310,1311],{"class":87},"      dts: ",[81,1313,1314],{"class":373},"true",[81,1316,207],{"class":87},[81,1318,1319],{"class":83,"line":670},[81,1320,1321],{"class":87},"      resolvers: [\n",[81,1323,1324,1327],{"class":83,"line":675},[81,1325,1326],{"class":95},"        HuchetVueResolver",[81,1328,960],{"class":87},[81,1330,1331,1334],{"class":83,"line":680},[81,1332,1333],{"class":87},"          prefix: ",[81,1335,1336],{"class":102},"'U'\n",[81,1338,1339],{"class":83,"line":713},[81,1340,1341],{"class":87},"        }),\n",[81,1343,1344],{"class":83,"line":738},[81,1345,1346],{"class":87},"      ],\n",[81,1348,1349],{"class":83,"line":743},[81,1350,1351],{"class":87},"    })\n",[81,1353,1354],{"class":83,"line":751},[81,1355,1356],{"class":87},"  ],\n",[81,1358,1359],{"class":83,"line":762},[81,1360,519],{"class":87},[19,1362,1363],{"start":129},[22,1364,1365,1366,1369,1370,404],{},"Add ",[78,1367,1368],{},"components.d.ts"," to ",[78,1371,1372],{},".gitignore",[70,1374,1376],{"className":342,"code":1375,"filename":1368,"language":344,"meta":76,"style":76},"echo \"components.d.ts\" >> .gitignore\n",[78,1377,1378],{"__ignoreMap":76},[81,1379,1380,1383,1386,1389],{"class":83,"line":84},[81,1381,1382],{"class":373},"echo",[81,1384,1385],{"class":102}," \"components.d.ts\"",[81,1387,1388],{"class":192}," >>",[81,1390,1391],{"class":102}," .gitignore\n",[59,1393,1394],{"color":313,"icon":314},[10,1395,1396,1397,1399],{},"This file is generated by ",[78,1398,1194],{}," to help your IDE understand the components and provide auto-completion.",[19,1401,1402],{"start":139},[22,1403,1214,1404,1407,1408,1410],{},[78,1405,1406],{},"src\u002FApp.vue"," to use the ",[78,1409,145],{}," component without importing it:",[70,1412,1414],{"className":72,"code":1413,"filename":1406,"language":75,"meta":76,"style":76},"\u003Ctemplate>\n  \u003Cdiv class=\"flex gap-6 p-6\">\n    \u003CUButton label=\"Hello World\" \u002F>\n    \u003CUButton label=\"Hello World\" variant=\"outline\" \u002F>\n  \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n",[78,1415,1416,1424,1441,1457,1479,1488],{"__ignoreMap":76},[81,1417,1418,1420,1422],{"class":83,"line":84},[81,1419,88],{"class":87},[81,1421,134],{"class":91},[81,1423,109],{"class":87},[81,1425,1426,1428,1431,1434,1436,1439],{"class":83,"line":112},[81,1427,142],{"class":87},[81,1429,1430],{"class":91},"div",[81,1432,1433],{"class":95}," class",[81,1435,99],{"class":87},[81,1437,1438],{"class":102},"\"flex gap-6 p-6\"",[81,1440,109],{"class":87},[81,1442,1443,1446,1448,1450,1452,1455],{"class":83,"line":122},[81,1444,1445],{"class":87},"    \u003C",[81,1447,145],{"class":91},[81,1449,148],{"class":95},[81,1451,99],{"class":87},[81,1453,1454],{"class":102},"\"Hello World\"",[81,1456,156],{"class":87},[81,1458,1459,1461,1463,1465,1467,1469,1472,1474,1477],{"class":83,"line":129},[81,1460,1445],{"class":87},[81,1462,145],{"class":91},[81,1464,148],{"class":95},[81,1466,99],{"class":87},[81,1468,1454],{"class":102},[81,1470,1471],{"class":95}," variant",[81,1473,99],{"class":87},[81,1475,1476],{"class":102},"\"outline\"",[81,1478,156],{"class":87},[81,1480,1481,1484,1486],{"class":83,"line":139},[81,1482,1483],{"class":87},"  \u003C\u002F",[81,1485,1430],{"class":91},[81,1487,109],{"class":87},[81,1489,1490,1492,1494],{"class":83,"line":159},[81,1491,115],{"class":87},[81,1493,134],{"class":91},[81,1495,109],{"class":87},[10,1497,1498,1499,1501],{},"That's it! The ",[78,1500,145],{}," component is automatically imported for ease of use.",[48,1503,1505],{"id":1504},"nuxt-module","Nuxt module",[10,1507,1508],{},"Nuxt transforms web development with Vue.js by providing an extended configuration and module system. Building a Nuxt module for our component library requires minimal effort and eliminates setup for developers. Let's dive into it.",[325,1510,1512],{"id":1511},"building-the-module","Building the module",[10,1514,1515,1516,1519,1520,339],{},"Start by creating a ",[78,1517,1518],{},"nuxt.ts"," file in the ",[78,1521,338],{},[70,1523,1525],{"className":342,"code":1524,"filename":1518,"language":344,"meta":76,"style":76},"touch nuxt.ts\n",[78,1526,1527],{"__ignoreMap":76},[81,1528,1529,1531],{"class":83,"line":84},[81,1530,351],{"class":95},[81,1532,1533],{"class":102}," nuxt.ts\n",[10,1535,1536],{},"Install the necessary Nuxt packages and Tailwind CSS:",[70,1538,1540],{"className":342,"code":1539,"filename":1176,"language":344,"meta":76,"style":76},"pnpm add -D @nuxt\u002Fkit @nuxt\u002Fschema && pnpm add tailwindcss@next @tailwindcss\u002Fvite@next @tailwindcss\u002Fpostcss@next\n",[78,1541,1542],{"__ignoreMap":76},[81,1543,1544,1546,1548,1550,1553,1556,1558,1560,1562,1565,1568],{"class":83,"line":84},[81,1545,558],{"class":95},[81,1547,561],{"class":102},[81,1549,564],{"class":373},[81,1551,1552],{"class":102}," @nuxt\u002Fkit",[81,1554,1555],{"class":102}," @nuxt\u002Fschema",[81,1557,555],{"class":87},[81,1559,558],{"class":95},[81,1561,561],{"class":102},[81,1563,1564],{"class":102}," tailwindcss@next",[81,1566,1567],{"class":102}," @tailwindcss\u002Fvite@next",[81,1569,1570],{"class":102}," @tailwindcss\u002Fpostcss@next\n",[10,1572,1573],{},"Then, create the module:",[70,1575,1577],{"className":183,"code":1576,"filename":74,"language":185,"meta":76,"style":76},"import type { } from '@nuxt\u002Fschema' \u002F\u002F Mandatory to avoid a bug when building\nimport { addComponent, addVitePlugin, defineNuxtModule } from '@nuxt\u002Fkit'\n\nimport { components } from '.\u002Fcomponents'\n\nexport interface ModuleOptions {\n  prefix: string\n}\n\nexport default defineNuxtModule\u003CModuleOptions>({\n  meta: {\n    name: '@barbapapazes\u002Fhuchet-vue',\n    configKey: 'huchet',\n    compatibility: {\n      nuxt: '>=3.0.0',\n    },\n  },\n  defaults: {\n    prefix: '',\n  },\n  async setup(options, nuxt) {\n    if (nuxt.options.builder === '@nuxt\u002Fvite-builder') {\n      const Tailwind = await import('@tailwindcss\u002Fvite').then(r => r.default)\n      addVitePlugin(Tailwind())\n    }\n    else {\n      nuxt.options.postcss.plugins['@tailwindcss\u002Fpostcss'] = {}\n    }\n\n    for (const component of components) {\n      addComponent({\n        name: `${options.prefix}${component}`,\n        export: component,\n        filePath: '@barbapapazes\u002Fhuchet-vue',\n      })\n    }\n  },\n})\n",[78,1578,1579,1596,1608,1612,1622,1626,1637,1645,1649,1653,1670,1675,1684,1694,1699,1709,1713,1717,1722,1732,1736,1755,1771,1809,1822,1826,1833,1849,1853,1857,1876,1884,1910,1916,1926,1932,1937,1942],{"__ignoreMap":76},[81,1580,1581,1583,1585,1588,1590,1593],{"class":83,"line":84},[81,1582,249],{"class":192},[81,1584,586],{"class":192},[81,1586,1587],{"class":87}," { } ",[81,1589,261],{"class":192},[81,1591,1592],{"class":102}," '@nuxt\u002Fschema'",[81,1594,1595],{"class":625}," \u002F\u002F Mandatory to avoid a bug when building\n",[81,1597,1598,1600,1603,1605],{"class":83,"line":112},[81,1599,249],{"class":192},[81,1601,1602],{"class":87}," { addComponent, addVitePlugin, defineNuxtModule } ",[81,1604,261],{"class":192},[81,1606,1607],{"class":102}," '@nuxt\u002Fkit'\n",[81,1609,1610],{"class":83,"line":122},[81,1611,126],{"emptyLinePlaceholder":125},[81,1613,1614,1616,1618,1620],{"class":83,"line":129},[81,1615,249],{"class":192},[81,1617,443],{"class":87},[81,1619,261],{"class":192},[81,1621,448],{"class":102},[81,1623,1624],{"class":83,"line":139},[81,1625,126],{"emptyLinePlaceholder":125},[81,1627,1628,1630,1632,1635],{"class":83,"line":159},[81,1629,367],{"class":192},[81,1631,615],{"class":192},[81,1633,1634],{"class":95}," ModuleOptions",[81,1636,196],{"class":87},[81,1638,1639,1641,1643],{"class":83,"line":301},[81,1640,661],{"class":660},[81,1642,404],{"class":192},[81,1644,667],{"class":373},[81,1646,1647],{"class":83,"line":639},[81,1648,220],{"class":87},[81,1650,1651],{"class":83,"line":651},[81,1652,126],{"emptyLinePlaceholder":125},[81,1654,1655,1657,1659,1662,1664,1667],{"class":83,"line":657},[81,1656,367],{"class":192},[81,1658,685],{"class":192},[81,1660,1661],{"class":95}," defineNuxtModule",[81,1663,88],{"class":87},[81,1665,1666],{"class":95},"ModuleOptions",[81,1668,1669],{"class":87},">({\n",[81,1671,1672],{"class":83,"line":670},[81,1673,1674],{"class":87},"  meta: {\n",[81,1676,1677,1680,1682],{"class":83,"line":675},[81,1678,1679],{"class":87},"    name: ",[81,1681,872],{"class":102},[81,1683,207],{"class":87},[81,1685,1686,1689,1692],{"class":83,"line":680},[81,1687,1688],{"class":87},"    configKey: ",[81,1690,1691],{"class":102},"'huchet'",[81,1693,207],{"class":87},[81,1695,1696],{"class":83,"line":713},[81,1697,1698],{"class":87},"    compatibility: {\n",[81,1700,1701,1704,1707],{"class":83,"line":738},[81,1702,1703],{"class":87},"      nuxt: ",[81,1705,1706],{"class":102},"'>=3.0.0'",[81,1708,207],{"class":87},[81,1710,1711],{"class":83,"line":743},[81,1712,898],{"class":87},[81,1714,1715],{"class":83,"line":751},[81,1716,1024],{"class":87},[81,1718,1719],{"class":83,"line":762},[81,1720,1721],{"class":87},"  defaults: {\n",[81,1723,1724,1727,1730],{"class":83,"line":786},[81,1725,1726],{"class":87},"    prefix: ",[81,1728,1729],{"class":102},"''",[81,1731,207],{"class":87},[81,1733,1734],{"class":83,"line":812},[81,1735,1024],{"class":87},[81,1737,1738,1741,1743,1745,1747,1749,1752],{"class":83,"line":837},[81,1739,1740],{"class":192},"  async",[81,1742,106],{"class":95},[81,1744,478],{"class":87},[81,1746,694],{"class":660},[81,1748,1110],{"class":87},[81,1750,1751],{"class":660},"nuxt",[81,1753,1754],{"class":87},") {\n",[81,1756,1757,1760,1763,1766,1769],{"class":83,"line":852},[81,1758,1759],{"class":192},"    if",[81,1761,1762],{"class":87}," (nuxt.options.builder ",[81,1764,1765],{"class":192},"===",[81,1767,1768],{"class":102}," '@nuxt\u002Fvite-builder'",[81,1770,1754],{"class":87},[81,1772,1773,1776,1779,1781,1784,1787,1789,1792,1795,1798,1800,1803,1806],{"class":83,"line":860},[81,1774,1775],{"class":192},"      const",[81,1777,1778],{"class":373}," Tailwind",[81,1780,377],{"class":192},[81,1782,1783],{"class":192}," await",[81,1785,1786],{"class":192}," import",[81,1788,478],{"class":87},[81,1790,1791],{"class":102},"'@tailwindcss\u002Fvite'",[81,1793,1794],{"class":87},").",[81,1796,1797],{"class":95},"then",[81,1799,478],{"class":87},[81,1801,1802],{"class":660},"r",[81,1804,1805],{"class":192}," =>",[81,1807,1808],{"class":87}," r.default)\n",[81,1810,1811,1814,1816,1819],{"class":83,"line":866},[81,1812,1813],{"class":95},"      addVitePlugin",[81,1815,478],{"class":87},[81,1817,1818],{"class":95},"Tailwind",[81,1820,1821],{"class":87},"())\n",[81,1823,1824],{"class":83,"line":877},[81,1825,1125],{"class":87},[81,1827,1828,1831],{"class":83,"line":883},[81,1829,1830],{"class":192},"    else",[81,1832,196],{"class":87},[81,1834,1835,1838,1841,1844,1846],{"class":83,"line":889},[81,1836,1837],{"class":87},"      nuxt.options.postcss.plugins[",[81,1839,1840],{"class":102},"'@tailwindcss\u002Fpostcss'",[81,1842,1843],{"class":87},"] ",[81,1845,99],{"class":192},[81,1847,1848],{"class":87}," {}\n",[81,1850,1851],{"class":83,"line":895},[81,1852,1125],{"class":87},[81,1854,1855],{"class":83,"line":901},[81,1856,126],{"emptyLinePlaceholder":125},[81,1858,1859,1862,1864,1867,1870,1873],{"class":83,"line":907},[81,1860,1861],{"class":192},"    for",[81,1863,691],{"class":87},[81,1865,1866],{"class":192},"const",[81,1868,1869],{"class":373}," component",[81,1871,1872],{"class":192}," of",[81,1874,1875],{"class":87}," components) {\n",[81,1877,1879,1882],{"class":83,"line":1878},31,[81,1880,1881],{"class":95},"      addComponent",[81,1883,960],{"class":87},[81,1885,1887,1890,1893,1895,1897,1899,1902,1905,1908],{"class":83,"line":1886},32,[81,1888,1889],{"class":87},"        name: ",[81,1891,1892],{"class":102},"`${",[81,1894,694],{"class":87},[81,1896,533],{"class":102},[81,1898,722],{"class":87},[81,1900,1901],{"class":102},"}${",[81,1903,1904],{"class":87},"component",[81,1906,1907],{"class":102},"}`",[81,1909,207],{"class":87},[81,1911,1913],{"class":83,"line":1912},33,[81,1914,1915],{"class":87},"        export: component,\n",[81,1917,1919,1922,1924],{"class":83,"line":1918},34,[81,1920,1921],{"class":87},"        filePath: ",[81,1923,872],{"class":102},[81,1925,207],{"class":87},[81,1927,1929],{"class":83,"line":1928},35,[81,1930,1931],{"class":87},"      })\n",[81,1933,1935],{"class":83,"line":1934},36,[81,1936,1125],{"class":87},[81,1938,1940],{"class":83,"line":1939},37,[81,1941,1024],{"class":87},[81,1943,1945],{"class":83,"line":1944},38,[81,1946,519],{"class":87},[10,1948,1949],{},"This plugin simplifies Tailwind CSS setup, using either Vite or PostCSS depending on the Nuxt builder.",[10,1951,1952],{},"The second part auto-imports components into the Nuxt system using the Unimport framework, allowing prefix customization like the Unplugin Vue Components resolver.",[10,1954,527,1955,1960,1961,533],{},[25,1956,1959],{"href":1957,"rel":1958},"https:\u002F\u002Fgithub.com\u002Funovue\u002Fradix-vue\u002Ftree\u002Fmain\u002Fpackages\u002Fplugins\u002Fsrc\u002Fnuxt",[29],"Radix Vue Nuxt module"," and ",[25,1962,1965],{"href":1963,"rel":1964},"https:\u002F\u002Fgithub.com\u002Fnuxt\u002Fui",[29],"Nuxt UI 3 module",[10,1967,1968,1969,1971,1972,404],{},"Add an entry in ",[78,1970,573],{}," and export it in ",[78,1973,1034],{},[70,1975,1977],{"className":917,"code":1976,"filename":1034,"language":185,"meta":76,"style":76},"import { resolve } from 'node:path'\n\nexport default defineConfig({\n  build: {\n    lib: {\n      entry: {\n        index: resolve(__dirname, 'src\u002Findex.ts'),\n        resolver: resolve(__dirname, 'src\u002Fresolver.ts'),\n        nuxt: resolve(__dirname, 'src\u002Fnuxt.ts'), \u002F\u002F [!code ++]\n      },\n    },\n    rollupOptions: {\n      external: ['vue', '@nuxt\u002Fkit', '@tailwindcss\u002Fvite'], \u002F\u002F [!code ++]\n    },\n  },\n})\n",[78,1978,1979,1989,1993,2003,2007,2011,2015,2027,2039,2054,2058,2062,2067,2088,2092,2096],{"__ignoreMap":76},[81,1980,1981,1983,1985,1987],{"class":83,"line":84},[81,1982,249],{"class":192},[81,1984,927],{"class":87},[81,1986,261],{"class":192},[81,1988,932],{"class":102},[81,1990,1991],{"class":83,"line":112},[81,1992,126],{"emptyLinePlaceholder":125},[81,1994,1995,1997,1999,2001],{"class":83,"line":122},[81,1996,367],{"class":192},[81,1998,685],{"class":192},[81,2000,957],{"class":95},[81,2002,960],{"class":87},[81,2004,2005],{"class":83,"line":129},[81,2006,965],{"class":87},[81,2008,2009],{"class":83,"line":139},[81,2010,970],{"class":87},[81,2012,2013],{"class":83,"line":159},[81,2014,975],{"class":87},[81,2016,2017,2019,2021,2023,2025],{"class":83,"line":301},[81,2018,980],{"class":87},[81,2020,983],{"class":95},[81,2022,986],{"class":87},[81,2024,989],{"class":102},[81,2026,992],{"class":87},[81,2028,2029,2031,2033,2035,2037],{"class":83,"line":639},[81,2030,1000],{"class":87},[81,2032,983],{"class":95},[81,2034,986],{"class":87},[81,2036,1007],{"class":102},[81,2038,992],{"class":87},[81,2040,2042,2045,2047,2049,2052],{"class":2041,"line":651},[83,996,997],[81,2043,2044],{"class":87},"        nuxt: ",[81,2046,983],{"class":95},[81,2048,986],{"class":87},[81,2050,2051],{"class":102},"'src\u002Fnuxt.ts'",[81,2053,1010],{"class":87},[81,2055,2056],{"class":83,"line":657},[81,2057,1015],{"class":87},[81,2059,2060],{"class":83,"line":670},[81,2061,898],{"class":87},[81,2063,2064],{"class":83,"line":675},[81,2065,2066],{"class":87},"    rollupOptions: {\n",[81,2068,2070,2073,2076,2078,2081,2083,2085],{"class":2069,"line":680},[83,996,997],[81,2071,2072],{"class":87},"      external: [",[81,2074,2075],{"class":102},"'vue'",[81,2077,1110],{"class":87},[81,2079,2080],{"class":102},"'@nuxt\u002Fkit'",[81,2082,1110],{"class":87},[81,2084,1791],{"class":102},[81,2086,2087],{"class":87},"], ",[81,2089,2090],{"class":83,"line":713},[81,2091,898],{"class":87},[81,2093,2094],{"class":83,"line":738},[81,2095,1024],{"class":87},[81,2097,2098],{"class":83,"line":743},[81,2099,519],{"class":87},[10,2101,2102,2103,1960,2106,533],{},"Make sure to externalize ",[78,2104,2105],{},"@nuxt\u002Fkit",[78,2107,2108],{},"@tailwindcss\u002Fvite",[70,2110,2113],{"className":2111,"code":2112,"filename":74,"language":1039,"meta":76,"style":76},"language-json shiki shiki-themes github-light github-light github-dark","{\n  \"exports\": {\n    \".\": {\n      \"types\": \".\u002Fdist\u002Findex.d.ts\",\n      \"import\": \".\u002Fdist\u002Findex.mjs\"\n    },\n    \".\u002Fresolver\": {\n      \"types\": \".\u002Fdist\u002Fresolver.d.ts\",\n      \"import\": \".\u002Fdist\u002Fresolver.mjs\"\n    },\n    \".\u002Fnuxt\": {\n      \"types\": \".\u002Fdist\u002Fnuxt.d.ts\",\n      \"import\": \".\u002Fdist\u002Fnuxt.mjs\"\n    }\n  },\n  \"main\": \".\u002Fdist\u002Findex.mjs\",\n  \"types\": \"dist\u002Findex.d.ts\"\n}\n",[78,2114,2115,2119,2125,2131,2141,2149,2153,2159,2169,2178,2182,2189,2200,2209,2213,2217,2227,2235],{"__ignoreMap":76},[81,2116,2117],{"class":83,"line":84},[81,2118,1046],{"class":87},[81,2120,2121,2123],{"class":83,"line":112},[81,2122,1051],{"class":373},[81,2124,1054],{"class":87},[81,2126,2127,2129],{"class":83,"line":122},[81,2128,1059],{"class":373},[81,2130,1054],{"class":87},[81,2132,2133,2135,2137,2139],{"class":83,"line":129},[81,2134,1066],{"class":373},[81,2136,1069],{"class":87},[81,2138,1072],{"class":102},[81,2140,207],{"class":87},[81,2142,2143,2145,2147],{"class":83,"line":139},[81,2144,1079],{"class":373},[81,2146,1069],{"class":87},[81,2148,1084],{"class":102},[81,2150,2151],{"class":83,"line":159},[81,2152,898],{"class":87},[81,2154,2155,2157],{"class":83,"line":301},[81,2156,1094],{"class":373},[81,2158,1054],{"class":87},[81,2160,2161,2163,2165,2167],{"class":83,"line":639},[81,2162,1066],{"class":373},[81,2164,1069],{"class":87},[81,2166,1107],{"class":102},[81,2168,207],{"class":87},[81,2170,2171,2173,2175],{"class":83,"line":651},[81,2172,1079],{"class":373},[81,2174,1069],{"class":87},[81,2176,2177],{"class":102},"\".\u002Fdist\u002Fresolver.mjs\"\n",[81,2179,2180],{"class":83,"line":657},[81,2181,898],{"class":87},[81,2183,2184,2187],{"class":83,"line":670},[81,2185,2186],{"class":373},"    \".\u002Fnuxt\"",[81,2188,1054],{"class":87},[81,2190,2191,2193,2195,2198],{"class":83,"line":675},[81,2192,1066],{"class":373},[81,2194,1069],{"class":87},[81,2196,2197],{"class":102},"\".\u002Fdist\u002Fnuxt.d.ts\"",[81,2199,207],{"class":87},[81,2201,2202,2204,2206],{"class":83,"line":680},[81,2203,1079],{"class":373},[81,2205,1069],{"class":87},[81,2207,2208],{"class":102},"\".\u002Fdist\u002Fnuxt.mjs\"\n",[81,2210,2211],{"class":83,"line":713},[81,2212,1125],{"class":87},[81,2214,2215],{"class":83,"line":738},[81,2216,1024],{"class":87},[81,2218,2219,2221,2223,2225],{"class":83,"line":743},[81,2220,1134],{"class":373},[81,2222,1069],{"class":87},[81,2224,1139],{"class":102},[81,2226,207],{"class":87},[81,2228,2229,2231,2233],{"class":83,"line":751},[81,2230,1146],{"class":373},[81,2232,1069],{"class":87},[81,2234,1151],{"class":102},[81,2236,2237],{"class":83,"line":762},[81,2238,220],{"class":87},[325,2240,2242],{"id":2241},"using-the-module","Using the module",[10,2244,2245],{},"With the Nuxt module in place, let's set up a way to test its functionality. We'll create a new Nuxt playground, install the package, and configure it.",[19,2247,2248],{},[22,2249,2250],{},"Create a new Nuxt project from the root directory:",[70,2252,2254],{"className":342,"code":2253,"filename":1176,"language":344,"meta":76,"style":76},"npx nuxi init .\u002Fplayground\u002Fnuxt\n",[78,2255,2256],{"__ignoreMap":76},[81,2257,2258,2261,2264,2267],{"class":83,"line":84},[81,2259,2260],{"class":95},"npx",[81,2262,2263],{"class":102}," nuxi",[81,2265,2266],{"class":102}," init",[81,2268,2269],{"class":102}," .\u002Fplayground\u002Fnuxt\n",[59,2271,2272],{"color":313,"icon":314},[10,2273,2274,2275,2278,2279,2282,2283,2285,2286,2289],{},"Modify the ",[78,2276,2277],{},"postinstall"," script to ",[78,2280,2281],{},"dev:prepare"," in Nuxt's ",[78,2284,1034],{}," to avoid errors after a package installation. Rename it since ",[78,2287,2288],{},"prepare"," is reserved by npm.",[19,2291,2292],{"start":112},[22,2293,2294],{},"Install the component library:",[70,2296,2298],{"className":342,"code":2297,"filename":1034,"language":344,"meta":76,"style":76},"cd .\u002Fplayground\u002Fnuxt && pnpm add ..\u002F..\u002Fpackages\u002Fhuchet-vue\n",[78,2299,2300],{"__ignoreMap":76},[81,2301,2302,2304,2307,2309,2311,2313],{"class":83,"line":84},[81,2303,1183],{"class":373},[81,2305,2306],{"class":102}," .\u002Fplayground\u002Fnuxt",[81,2308,555],{"class":87},[81,2310,558],{"class":95},[81,2312,561],{"class":102},[81,2314,2315],{"class":102}," ..\u002F..\u002Fpackages\u002Fhuchet-vue\n",[19,2317,2318],{"start":122},[22,2319,2320,2321,2324],{},"Duplicate the ",[78,2322,2323],{},"App.vue"," from the Vue playground to the Nuxt playground:",[70,2326,2328],{"className":342,"code":2327,"filename":2323,"language":344,"meta":76,"style":76},"cp ..\u002Fvue\u002Fsrc\u002FApp.vue .\u002Fapp.vue\n",[78,2329,2330],{"__ignoreMap":76},[81,2331,2332,2335,2338],{"class":83,"line":84},[81,2333,2334],{"class":95},"cp",[81,2336,2337],{"class":102}," ..\u002Fvue\u002Fsrc\u002FApp.vue",[81,2339,2340],{"class":102}," .\u002Fapp.vue\n",[19,2342,2343],{"start":129},[22,2344,2345,2346,404],{},"Add the module in ",[78,2347,2348],{},"nuxt.config.ts",[70,2350,2352],{"className":183,"code":2351,"filename":2348,"language":185,"meta":76,"style":76},"export default defineNuxtConfig({\n  modules: ['@barbapapazes\u002Fhuchet-vue\u002Fnuxt'],\n  css: ['~\u002Fassets\u002Fcss\u002Fmain.css'],\n  huchet: {\n    prefix: 'U',\n  },\n  compatibilityDate: '2024-11-01',\n  devtools: { enabled: true },\n})\n",[78,2353,2354,2365,2376,2386,2391,2400,2404,2414,2424],{"__ignoreMap":76},[81,2355,2356,2358,2360,2363],{"class":83,"line":84},[81,2357,367],{"class":192},[81,2359,685],{"class":192},[81,2361,2362],{"class":95}," defineNuxtConfig",[81,2364,960],{"class":87},[81,2366,2367,2370,2373],{"class":83,"line":112},[81,2368,2369],{"class":87},"  modules: [",[81,2371,2372],{"class":102},"'@barbapapazes\u002Fhuchet-vue\u002Fnuxt'",[81,2374,2375],{"class":87},"],\n",[81,2377,2378,2381,2384],{"class":83,"line":122},[81,2379,2380],{"class":87},"  css: [",[81,2382,2383],{"class":102},"'~\u002Fassets\u002Fcss\u002Fmain.css'",[81,2385,2375],{"class":87},[81,2387,2388],{"class":83,"line":129},[81,2389,2390],{"class":87},"  huchet: {\n",[81,2392,2393,2395,2398],{"class":83,"line":139},[81,2394,1726],{"class":87},[81,2396,2397],{"class":102},"'U'",[81,2399,207],{"class":87},[81,2401,2402],{"class":83,"line":159},[81,2403,1024],{"class":87},[81,2405,2406,2409,2412],{"class":83,"line":301},[81,2407,2408],{"class":87},"  compatibilityDate: ",[81,2410,2411],{"class":102},"'2024-11-01'",[81,2413,207],{"class":87},[81,2415,2416,2419,2421],{"class":83,"line":639},[81,2417,2418],{"class":87},"  devtools: { enabled: ",[81,2420,1314],{"class":373},[81,2422,2423],{"class":87}," },\n",[81,2425,2426],{"class":83,"line":651},[81,2427,519],{"class":87},[59,2429,2430],{"color":313,"icon":314},[10,2431,2432,2433,2436],{},"Include the CSS file using the ",[78,2434,2435],{},"css"," property for Tailwind CSS to function.",[19,2438,2439],{"start":139},[22,2440,2441,2442,404],{},"Create the CSS file in ",[78,2443,2444],{},"assets\u002Fcss\u002Fmain.css",[70,2446,2448],{"className":342,"code":2447,"filename":2444,"language":344,"meta":76,"style":76},"mkdir -p assets\u002Fcss && touch assets\u002Fcss\u002Fmain.css && echo \"@import 'tailwindcss';\" >> assets\u002Fcss\u002Fmain.css\n",[78,2449,2450],{"__ignoreMap":76},[81,2451,2452,2455,2458,2461,2463,2465,2468,2470,2472,2475,2477],{"class":83,"line":84},[81,2453,2454],{"class":95},"mkdir",[81,2456,2457],{"class":373}," -p",[81,2459,2460],{"class":102}," assets\u002Fcss",[81,2462,555],{"class":87},[81,2464,351],{"class":95},[81,2466,2467],{"class":102}," assets\u002Fcss\u002Fmain.css",[81,2469,555],{"class":87},[81,2471,1382],{"class":373},[81,2473,2474],{"class":102}," \"@import 'tailwindcss';\"",[81,2476,1388],{"class":192},[81,2478,2479],{"class":102}," assets\u002Fcss\u002Fmain.css\n",[19,2481,2482],{"start":159},[22,2483,2484],{},"Launch the Nuxt project:",[70,2486,2488],{"className":342,"code":2487,"filename":1176,"language":344,"meta":76,"style":76},"pnpm dev\n",[78,2489,2490],{"__ignoreMap":76},[81,2491,2492,2494],{"class":83,"line":84},[81,2493,558],{"class":95},[81,2495,2496],{"class":102}," dev\n",[10,2498,2499],{},"Voila! You can now use the component library in a Nuxt project seamlessly, with auto-imported components and fully-functional Tailwind CSS.",[10,2501,2502,2503,2505],{},"The ",[14,2504,42],{}," developer experience, enriched by the module system, significantly simplifies developers' lives. I'm confident you will appreciate it too.",[2507,2508,2509],"style",{},"html pre.shiki code .sxrX7, html code.shiki .sxrX7{--shiki-light:#24292E;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sovSZ, html code.shiki .sovSZ{--shiki-light:#22863A;--shiki-default:#22863A;--shiki-dark:#85E89D}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 .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 .sBjJW, html code.shiki .sBjJW{--shiki-light:#005CC5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}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}",{"title":76,"searchDepth":112,"depth":112,"links":2511},[2512,2516],{"id":50,"depth":112,"text":51,"children":2513},[2514,2515],{"id":327,"depth":122,"text":328},{"id":1163,"depth":122,"text":1164},{"id":1504,"depth":112,"text":1505,"children":2517},[2518,2519],{"id":1511,"depth":122,"text":1512},{"id":2241,"depth":122,"text":2242},"8b808104-15ac-42ca-9535-cef0996ddf66","2024-11-24","Discover how to seamlessly integrate a Vue.js component library using Unplugin Vue Components and Nuxt Module, enhancing usability and developer experience.","md",null,{},"\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fenhancing-integration-with-unplugin-and-nuxt-module","---\ncontentId: 8b808104-15ac-42ca-9535-cef0996ddf66\npart: 7\ntitle: \"Enhancing Integration with Unplugin and Nuxt Module\"\ndescription: \"Discover how to seamlessly integrate a Vue.js component library using Unplugin Vue Components and Nuxt Module, enhancing usability and developer experience.\"\ndate: 2024-11-24\nseriesSlug: the-complete-guide-to-building-a-vue-js-component-library\n---\n\nHaving a robust component library is a great start, but integrating it into the **Vue.js ecosystem** takes it to another level. In this ecosystem, two main tools stand out:\n\n1. [**Unplugin Vue Components**](https:\u002F\u002Fgithub.com\u002Funplugin\u002Funplugin-vue-components): A bundler plugin for on-demand components that are auto-imported, fully typed, and tree-shakable.\n2. [**Nuxt**](https:\u002F\u002Fnuxt.com): An open-source framework based on Vue.js that simplifies and empowers web development.\n\nAlthough our component library can function without integration into these tools, I'm firmly convinced that integration will enhance its power and ease of use. I'm devoted to providing the best developer experience possible, and I'm sure you will find it invaluable.\n\n## Unplugin Vue component resolver\n\nBefore building the resolver, it's essential to understand how **Unplugin Vue Components** works. This will clarify what a resolver does and its functionality.\n\n::callout{icon=\"i-ph-lightbulb-duotone\" color=\"success\"}\nIf you have any questions, please comment below, and I'll be happy to assist.\n::\n\nConsider this component:\n\n```vue [Example]\n\u003Cscript lang=\"ts\" setup>\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003CUButton label=\"Click me\" \u002F>\n\u003C\u002Ftemplate>\n```\n\nNotice that there's no import statement for the `UButton` component. Unplugin Vue Components scans the template and identifies non-standard HTML tags to find them in its component list. This list can be manually fed or automatically populated using a resolver.\n\nA resolver is a function that receives a component name and returns its import path if it matches the resolver's internal list. This allows selective auto-import of components or adding prefixes to component names.\n\nIn our example, a resolver might resolve the `UButton` component as:\n\n```ts [Example]\nreturn {\n  name: 'Button',\n  from: '@nuxt\u002Fui'\n}\n```\n\nUnplugin Vue Components would transform the component by injecting the import statement:\n\n```vue [Example]\n\u003Cscript lang=\"ts\" setup>\nimport { Button as UButton } from '@nuxt\u002Fui'\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003CUButton label=\"Click me\" \u002F>\n\u003C\u002Ftemplate>\n```\n\nSimple, right? Now, let's build our resolver.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nTo deepen your understanding of Vite, try the [vite-plugin-inspector](https:\u002F\u002Fgithub.com\u002Fantfu-collective\u002Fvite-plugin-inspect), which lets you inspect modifications made by each plugin.\n::\n\n### Building the resolver\n\nFirst, gather all your library components in a `src\u002Fcomponents.ts` file within the `packages\u002Fhuchet-vue` folder:\n\n```bash [src\u002Fcomponents.ts]\ntouch src\u002Fcomponents.ts\n```\n\nThen export an array of all components:\n\n```ts [Example]\nexport const components = [\n  'Button'\n]\n```\n\nTo ensure updates, create a test that verifies the exported components match those in the `components` folder. Create a `src\u002Findex.test.ts` file in `packages\u002Fhuchet-vue`:\n\n```bash [src\u002Findex.test.ts]\ntouch src\u002Findex.test.ts\n```\n\nAdd this test to verify component exports:\n\n```ts [Example]\nimport { expect, it } from 'vitest'\nimport { components } from '.\u002Fcomponents'\nimport * as Huchet from '.\u002Findex'\n\nit('should expose the correct components', () => {\n  expect(Object.keys(Huchet)).toEqual(Object.values(components))\n})\n```\n\nThis test prevents missed updates when components change.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nInspired by [Radix Vue](https:\u002F\u002Fgithub.com\u002Funovue\u002Fradix-vue\u002Fblob\u002Fmain\u002Fpackages\u002Fradix-vue\u002Fsrc\u002Findex.test.ts).\n::\n\nNext, create a `src\u002Fresolver.ts` for the Unplugin Vue Components resolver and install it as a dev dependency:\n\n```bash [src\u002Fresolver.ts]\ntouch src\u002Fresolver.ts && pnpm add -D unplugin-vue-components\n```\n\nThe resolver function initiates in `vite.config.ts`, allowing developers to pass options like a prefix for component names. It resolves component names and returns import paths if they match:\n\n```ts [vite.config.ts]\nimport type { ComponentResolver } from 'unplugin-vue-components'\nimport { components } from '.\u002Fcomponents'\n\nexport interface ResolverOptions {\n  \u002F**\n   * prefix for components used in templates\n   *\n   * @defaultValue \"\"\n   *\u002F\n  prefix?: string\n}\n\nexport default function (options: ResolverOptions = {}): ComponentResolver {\n  const { prefix = '' } = options\n\n  return {\n    type: 'component',\n    resolve: (name: string) => {\n      if (name.toLowerCase().startsWith(prefix.toLowerCase())) {\n        const componentName = name.substring(prefix.length)\n        if (components.includes(componentName)) {\n          return {\n            name: componentName,\n            from: '@barbapapazes\u002Fhuchet-vue',\n          }\n        }\n      }\n    },\n  }\n}\n```\n\nTo ensure the resolver is built, add it as an entry point in `vite.config.ts`:\n\n```ts [vite.config.ts]\nimport { resolve } from 'node:path'\nimport { defineConfig } from 'vite'\n\nexport default defineConfig({\n  build: {\n    lib: {\n      entry: {\n        index: resolve(__dirname, 'src\u002Findex.ts'),\n        resolver: resolve(__dirname, 'src\u002Fresolver.ts'), \u002F\u002F [!code ++]\n      },\n    },\n  },\n})\n```\n\nFinally, export the resolver in `package.json`:\n\n```json [package.json]\n{\n  \"exports\": {\n    \".\": {\n      \"types\": \".\u002Fdist\u002Findex.d.ts\",\n      \"import\": \".\u002Fdist\u002Findex.mjs\"\n    },\n    \".\u002Fresolver\": { \u002F\u002F [!code ++]\n      \"types\": \".\u002Fdist\u002Fresolver.d.ts\", \u002F\u002F [!code ++]\n      \"import\": \".\u002Fdist\u002Fresolver.mjs\" \u002F\u002F [!code ++]\n    }\n  },\n  \"main\": \".\u002Fdist\u002Findex.mjs\",\n  \"types\": \"dist\u002Findex.d.ts\"\n}\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nRebuild the project to ensure the new entry point is accessible.\n::\n\n### Using the resolver\n\nWith the resolver ready, let's test it in our playground project:\n\n1. Navigate to the playground folder:\n\n```bash [terminal]\ncd ..\u002F..\u002Fplayground\u002Fvue\n```\n\n2. Install `unplugin-vue-components`:\n\n```bash [terminal]\npnpm add -D unplugin-vue-components\n```\n\n3. Update `vite.config.ts` to use the resolver with a `U` prefix:\n\n```ts [vite.config.ts]\nimport HuchetVueResolver from '@barbapapazes\u002Fhuchet-vue\u002Fresolver'\nimport Vue from '@vitejs\u002Fplugin-vue'\nimport Components from 'unplugin-vue-components\u002Fvite'\nimport { defineConfig } from 'vite'\n\nexport default defineConfig({\n  plugins: [\n    Vue(),\n    Components({\n      dts: true,\n      resolvers: [\n        HuchetVueResolver({\n          prefix: 'U'\n        }),\n      ],\n    })\n  ],\n})\n```\n\n4. Add `components.d.ts` to `.gitignore`:\n\n```bash [components.d.ts]\necho \"components.d.ts\" >> .gitignore\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nThis file is generated by `unplugin-vue-components` to help your IDE understand the components and provide auto-completion.\n::\n\n5. Update `src\u002FApp.vue` to use the `UButton` component without importing it:\n\n```vue [src\u002FApp.vue]\n\u003Ctemplate>\n  \u003Cdiv class=\"flex gap-6 p-6\">\n    \u003CUButton label=\"Hello World\" \u002F>\n    \u003CUButton label=\"Hello World\" variant=\"outline\" \u002F>\n  \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n```\n\nThat's it! The `UButton` component is automatically imported for ease of use.\n\n## Nuxt module\n\nNuxt transforms web development with Vue.js by providing an extended configuration and module system. Building a Nuxt module for our component library requires minimal effort and eliminates setup for developers. Let's dive into it.\n\n### Building the module\n\nStart by creating a `nuxt.ts` file in the `packages\u002Fhuchet-vue` folder:\n\n```bash [nuxt.ts]\ntouch nuxt.ts\n```\n\nInstall the necessary Nuxt packages and Tailwind CSS:\n\n```bash [terminal]\npnpm add -D @nuxt\u002Fkit @nuxt\u002Fschema && pnpm add tailwindcss@next @tailwindcss\u002Fvite@next @tailwindcss\u002Fpostcss@next\n```\n\nThen, create the module:\n\n```ts [Example]\nimport type { } from '@nuxt\u002Fschema' \u002F\u002F Mandatory to avoid a bug when building\nimport { addComponent, addVitePlugin, defineNuxtModule } from '@nuxt\u002Fkit'\n\nimport { components } from '.\u002Fcomponents'\n\nexport interface ModuleOptions {\n  prefix: string\n}\n\nexport default defineNuxtModule\u003CModuleOptions>({\n  meta: {\n    name: '@barbapapazes\u002Fhuchet-vue',\n    configKey: 'huchet',\n    compatibility: {\n      nuxt: '>=3.0.0',\n    },\n  },\n  defaults: {\n    prefix: '',\n  },\n  async setup(options, nuxt) {\n    if (nuxt.options.builder === '@nuxt\u002Fvite-builder') {\n      const Tailwind = await import('@tailwindcss\u002Fvite').then(r => r.default)\n      addVitePlugin(Tailwind())\n    }\n    else {\n      nuxt.options.postcss.plugins['@tailwindcss\u002Fpostcss'] = {}\n    }\n\n    for (const component of components) {\n      addComponent({\n        name: `${options.prefix}${component}`,\n        export: component,\n        filePath: '@barbapapazes\u002Fhuchet-vue',\n      })\n    }\n  },\n})\n```\n\nThis plugin simplifies Tailwind CSS setup, using either Vite or PostCSS depending on the Nuxt builder.\n\nThe second part auto-imports components into the Nuxt system using the Unimport framework, allowing prefix customization like the Unplugin Vue Components resolver.\n\nInspired by [Radix Vue Nuxt module](https:\u002F\u002Fgithub.com\u002Funovue\u002Fradix-vue\u002Ftree\u002Fmain\u002Fpackages\u002Fplugins\u002Fsrc\u002Fnuxt) and [Nuxt UI 3 module](https:\u002F\u002Fgithub.com\u002Fnuxt\u002Fui).\n\nAdd an entry in `vite.config.ts` and export it in `package.json`:\n\n```ts [package.json]\nimport { resolve } from 'node:path'\n\nexport default defineConfig({\n  build: {\n    lib: {\n      entry: {\n        index: resolve(__dirname, 'src\u002Findex.ts'),\n        resolver: resolve(__dirname, 'src\u002Fresolver.ts'),\n        nuxt: resolve(__dirname, 'src\u002Fnuxt.ts'), \u002F\u002F [!code ++]\n      },\n    },\n    rollupOptions: {\n      external: ['vue', '@nuxt\u002Fkit', '@tailwindcss\u002Fvite'], \u002F\u002F [!code ++]\n    },\n  },\n})\n```\n\nMake sure to externalize `@nuxt\u002Fkit` and `@tailwindcss\u002Fvite`.\n\n```json [Example]\n{\n  \"exports\": {\n    \".\": {\n      \"types\": \".\u002Fdist\u002Findex.d.ts\",\n      \"import\": \".\u002Fdist\u002Findex.mjs\"\n    },\n    \".\u002Fresolver\": {\n      \"types\": \".\u002Fdist\u002Fresolver.d.ts\",\n      \"import\": \".\u002Fdist\u002Fresolver.mjs\"\n    },\n    \".\u002Fnuxt\": {\n      \"types\": \".\u002Fdist\u002Fnuxt.d.ts\",\n      \"import\": \".\u002Fdist\u002Fnuxt.mjs\"\n    }\n  },\n  \"main\": \".\u002Fdist\u002Findex.mjs\",\n  \"types\": \"dist\u002Findex.d.ts\"\n}\n```\n\n### Using the module\n\nWith the Nuxt module in place, let's set up a way to test its functionality. We'll create a new Nuxt playground, install the package, and configure it.\n\n1. Create a new Nuxt project from the root directory:\n\n```bash [terminal]\nnpx nuxi init .\u002Fplayground\u002Fnuxt\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nModify the `postinstall` script to `dev:prepare` in Nuxt's `package.json` to avoid errors after a package installation. Rename it since `prepare` is reserved by npm.\n::\n\n2. Install the component library:\n\n```bash [package.json]\ncd .\u002Fplayground\u002Fnuxt && pnpm add ..\u002F..\u002Fpackages\u002Fhuchet-vue\n```\n\n3. Duplicate the `App.vue` from the Vue playground to the Nuxt playground:\n\n```bash [App.vue]\ncp ..\u002Fvue\u002Fsrc\u002FApp.vue .\u002Fapp.vue\n```\n\n4. Add the module in `nuxt.config.ts`:\n\n```ts [nuxt.config.ts]\nexport default defineNuxtConfig({\n  modules: ['@barbapapazes\u002Fhuchet-vue\u002Fnuxt'],\n  css: ['~\u002Fassets\u002Fcss\u002Fmain.css'],\n  huchet: {\n    prefix: 'U',\n  },\n  compatibilityDate: '2024-11-01',\n  devtools: { enabled: true },\n})\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nInclude the CSS file using the `css` property for Tailwind CSS to function.\n::\n\n5. Create the CSS file in `assets\u002Fcss\u002Fmain.css`:\n\n```bash [assets\u002Fcss\u002Fmain.css]\nmkdir -p assets\u002Fcss && touch assets\u002Fcss\u002Fmain.css && echo \"@import 'tailwindcss';\" >> assets\u002Fcss\u002Fmain.css\n```\n\n6. Launch the Nuxt project:\n\n```bash [terminal]\npnpm dev\n```\n\nVoila! You can now use the component library in a Nuxt project seamlessly, with auto-imported components and fully-functional Tailwind CSS.\n\nThe **Nuxt** developer experience, enriched by the module system, significantly simplifies developers' lives. I'm confident you will appreciate it too.\n",{"title":5,"description":2522},"the-complete-guide-to-building-a-vue-js-component-library",{"loc":2526},"series\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fenhancing-integration-with-unplugin-and-nuxt-module","E5sidFULP2YVLKmQsph8ptc9F6GZpZ-11t1qEkQGLfI",{"overview":2534,"chapters":2732},{"id":2535,"title":2536,"body":2537,"contentId":2715,"date":2521,"description":2716,"extension":2523,"github":2717,"meetTheInstructor":2720,"meta":2721,"navigation":125,"part":2524,"path":2722,"rawbody":2723,"robots":2524,"schemaOrg":2524,"seo":2724,"seriesSlug":2529,"sitemap":2725,"stem":2726,"subtitle":2727,"topics":2728,"__hash__":2731},"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":2538,"toc":2711},[2539,2542,2545,2557,2561,2564,2578,2582,2585,2698,2701,2705],[10,2540,2541],{},"Welcome! 👋",[10,2543,2544],{},"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,2546,2547,2548,2552,2553],{},"This series is somewhat of a sequel to the article ",[25,2549,2551],{"href":2550},"\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. ",[2554,2555,2556],"em",{},"You will learn how the most popular component libraries are constructed behind the scenes and how to create your own.",[2558,2559],"callout-read-more",{"id":2560},"f9754148-40bd-4df2-a144-f686e894b200",[10,2562,2563],{},"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,2565,2566,2567,2572,2573,533],{},"That's understandable. While ",[25,2568,2571],{"href":2569,"rel":2570},"https:\u002F\u002Fgithub.com\u002Funjs\u002Funbuild",[29],"unbuild"," is a powerful tool, it cannot match the flexibility, plugin ecosystem, and adoption of ",[25,2574,2577],{"href":2575,"rel":2576},"https:\u002F\u002Fvite.dev\u002F",[29],"Vite",[48,2579,2581],{"id":2580},"what-to-expect","What to expect",[10,2583,2584],{},"Throughout this series, we will address the following topics:",[19,2586,2587,2599,2631,2649,2666,2672,2684],{},[22,2588,2589,2592,2593,2598],{},[14,2590,2591],{},"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 ",[25,2594,2597],{"href":2595,"rel":2596},"https:\u002F\u002Feslint.org\u002F",[29],"ESLint"," to ensure code consistency.",[22,2600,2601,2604,2605,1110,2610,2615,2616,2621,2622,1960,2626,533],{},[14,2602,2603],{},"Building a First Component with Vue.js and Tailwind CSS",": We'll create our first component with ",[25,2606,2609],{"href":2607,"rel":2608},"https:\u002F\u002Fvuejs.org\u002F",[29],"Vue.js",[25,2611,2614],{"href":2612,"rel":2613},"https:\u002F\u002Ftailwindcss.com\u002F",[29],"Tailwind CSS",", and ",[25,2617,2620],{"href":2618,"rel":2619},"https:\u002F\u002Fwww.tailwind-variants.org\u002F",[29],"Tailwind Variants"," using the most advanced and powerful techniques employed in popular component libraries like ",[25,2623,532],{"href":2624,"rel":2625},"https:\u002F\u002Fwww.radix-vue.com\u002F",[29],[25,2627,2630],{"href":2628,"rel":2629},"https:\u002F\u002Fui.nuxt.com\u002F",[29],"Nuxt UI",[22,2632,2633,2636,2637,2642,2643,2648],{},[14,2634,2635],{},"A Better Development Experience with TypeScript and TSConfig",": We'll enhance our development experience by adding ",[25,2638,2641],{"href":2639,"rel":2640},"https:\u002F\u002Fwww.typescriptlang.org\u002F",[29],"TypeScript"," to our component library and configuring ",[25,2644,2647],{"href":2645,"rel":2646},"https:\u002F\u002Fwww.typescriptlang.org\u002Ftsconfig",[29],"TSConfig"," to ensure that our components are typed correctly and that we can take full advantage of TypeScript's features.",[22,2650,2651,2654,2655,1960,2660,2665],{},[14,2652,2653],{},"Automatic Component Testing with Vitest and Testing Library",": We'll write tests for our components using ",[25,2656,2659],{"href":2657,"rel":2658},"https:\u002F\u002Fvitest.dev\u002Fguide\u002F",[29],"Vitest",[25,2661,2664],{"href":2662,"rel":2663},"https:\u002F\u002Ftesting-library.com\u002F",[29],"Testing Library"," to ensure that our components function as expected. This is crucial for a professional component library that remains reliable over time.",[22,2667,2668,2671],{},[14,2669,2670],{},"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.",[22,2673,2674,2677,2678,2683],{},[14,2675,2676],{},"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 ",[25,2679,2682],{"href":2680,"rel":2681},"https:\u002F\u002Fhistoire.dev\u002F",[29],"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.",[22,2685,2686,2688,2689,2692,2693,2697],{},[14,2687,5],{},": We'll enhance the integration of our component library with the ecosystem by creating a Vite plugin with ",[25,2690,32],{"href":27,"rel":2691},[29]," and a ",[25,2694,1505],{"href":2695,"rel":2696},"https:\u002F\u002Fnuxt.com\u002Fdocs\u002Fguide\u002Fgoing-further\u002Fmodules",[29]," to utilize our components in a Nuxt application.",[10,2699,2700],{},"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? 😎",[48,2702,2704],{"id":2703},"chapters","Chapters",[2706,2707],"series-chapters-list",{"className":2708},[2709,2710],"mx-auto","max-w-5xl",{"title":76,"searchDepth":112,"depth":112,"links":2712},[2713,2714],{"id":2580,"depth":112,"text":2581},{"id":2703,"depth":112,"text":2704},"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":2718,"repository":2719},"huchet-vue","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":2536,"description":2716},{"loc":2722},"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.",[75,2729,2730],"vite","component library","2VSSnBlkuSLlt05n9MySLBFt6vBkgd7691eX-TK2cTs",[2733,2737,2741,2745,2749,2753,2757],{"contentId":2734,"title":2591,"description":2735,"path":2736,"part":84,"github":2524,"topics":2524},"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":2738,"title":2603,"description":2739,"path":2740,"part":112,"github":2524,"topics":2524},"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":2742,"title":2635,"description":2743,"path":2744,"part":122,"github":2524,"topics":2524},"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":2746,"title":2653,"description":2747,"path":2748,"part":129,"github":2524,"topics":2524},"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":2750,"title":2670,"description":2751,"path":2752,"part":139,"github":2524,"topics":2524},"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":2754,"title":2676,"description":2755,"path":2756,"part":159,"github":2524,"topics":2524},"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":2520,"title":5,"description":2522,"path":2526,"part":301,"github":2524,"topics":2524},1795016694972]