[{"data":1,"prerenderedAt":2231},["ShallowReactive",2],{"series-\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fcreating-a-playground-and-a-storybook-for-components":3,"series-context-\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library":2007},{"id":4,"title":5,"body":6,"contentId":1989,"date":1990,"description":1991,"extension":1992,"github":1993,"meetTheInstructor":1993,"meta":1994,"navigation":372,"part":386,"path":1995,"rawbody":1996,"robots":1993,"schemaOrg":1993,"seo":1997,"seriesSlug":1998,"sitemap":1999,"stem":2005,"subtitle":1993,"topics":1993,"__hash__":2006},"series\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fcreating-a-playground-and-a-storybook-for-components.md","Creating a Playground and a Storybook for Components",{"type":7,"value":8,"toc":1979},"minimark",[9,18,38,43,50,73,80,113,120,131,167,170,182,185,234,262,265,280,287,297,301,304,315,464,467,479,482,494,506,509,520,524,527,533,539,560,567,660,666,684,687,695,699,706,721,726,732,735,765,773,776,794,797,826,831,842,855,858,898,1149,1163,1169,1207,1215,1222,1287,1290,1300,1308,1312,1322,1334,1337,1351,1364,1586,1593,1596,1604,1612,1616,1619,1624,1636,1650,1728,1758,1763,1775,1778,1803,1809,1898,1907,1967,1972,1975],[10,11,12,13,17],"p",{},"We have components and tests, but until now, we've been unable to see them in action. It's time to create a ",[14,15,16],"strong",{},"playground"," for two key reasons:",[19,20,21,28],"ol",{},[22,23,24,27],"li",{},[14,25,26],{},"Testing",": We need to test our components in a real environment to ensure they work as expected. Writing a page with all components, their props, and slots helps create the best API and implement it efficiently. This approach minimizes frequent refactoring by providing a comprehensive view of the components.",[22,29,30,33,34,37],{},[14,31,32],{},"Visualizing",": Visualizing components is essential. While ",[14,35,36],{},"Tailwind CSS"," simplifies styling, it's impossible to fully grasp a component through code, especially complex ones with numerous variants or slots. A playground allows us to see components in action and test them in various scenarios.",[39,40,42],"h2",{"id":41},"setting-up-the-playground","Setting up the playground",[10,44,45,46,49],{},"First, create a new folder named ",[47,48,16],"code",{}," at the root of your project.",[51,52,58],"pre",{"className":53,"code":54,"filename":55,"language":56,"meta":57,"style":57},"language-bash shiki shiki-themes github-light github-light github-dark","mkdir playground\n","terminal","bash","",[47,59,60],{"__ignoreMap":57},[61,62,65,69],"span",{"class":63,"line":64},"line",1,[61,66,68],{"class":67},"snPdu","mkdir",[61,70,72],{"class":71},"sIIMD"," playground\n",[10,74,75,76,79],{},"Then, create a new ",[14,77,78],{},"Vite"," project in this folder, which will depend on our component library. Being in a monorepo simplifies this process.",[51,81,83],{"className":53,"code":82,"filename":55,"language":56,"meta":57,"style":57},"cd playground && pnpm create vite --template vue-ts\n",[47,84,85],{"__ignoreMap":57},[61,86,87,91,94,98,101,104,107,110],{"class":63,"line":64},[61,88,90],{"class":89},"sBjJW","cd",[61,92,93],{"class":71}," playground",[61,95,97],{"class":96},"sxrX7"," && ",[61,99,100],{"class":67},"pnpm",[61,102,103],{"class":71}," create",[61,105,106],{"class":71}," vite",[61,108,109],{"class":89}," --template",[61,111,112],{"class":71}," vue-ts\n",[10,114,115,116,119],{},"Name this project ",[47,117,118],{},"vue",".",[10,121,122,123,126,127,130],{},"Before installing dependencies, update the ",[47,124,125],{},"pnpm-workspace.yaml"," to include the ",[47,128,129],{},"playground\u002Fvue"," package. This allows the playground to access the component library.",[51,132,136],{"className":133,"code":134,"filename":125,"language":135,"meta":57,"style":57},"language-yaml shiki shiki-themes github-light github-light github-dark has-diff","packages:\n  - 'packages\u002F*'\n  - 'playground\u002F*' # [!code ++]\n","yaml",[47,137,138,147,156],{"__ignoreMap":57},[61,139,140,144],{"class":63,"line":64},[61,141,143],{"class":142},"sovSZ","packages",[61,145,146],{"class":96},":\n",[61,148,150,153],{"class":63,"line":149},2,[61,151,152],{"class":96},"  - ",[61,154,155],{"class":71},"'packages\u002F*'\n",[61,157,162,164],{"class":158,"line":161},[63,159,160],"diff","add",3,[61,163,152],{"class":96},[61,165,166],{"class":71},"'playground\u002F*'",[10,168,169],{},"Install the playground dependencies:",[51,171,173],{"className":53,"code":172,"filename":55,"language":56,"meta":57,"style":57},"pnpm install\n",[47,174,175],{"__ignoreMap":57},[61,176,177,179],{"class":63,"line":64},[61,178,100],{"class":67},[61,180,181],{"class":71}," install\n",[10,183,184],{},"In this Vue.js playground, remove unnecessary files, folders, and content:",[51,186,188],{"className":53,"code":187,"filename":55,"language":56,"meta":57,"style":57},"rm -rf .vscode .public src\u002F{assets,components}\necho \"\u003Ctemplate>\u003C\u002Ftemplate>\" > src\u002FApp.vue\necho \"\" > src\u002Fstyle.css\n",[47,189,190,207,222],{"__ignoreMap":57},[61,191,192,195,198,201,204],{"class":63,"line":64},[61,193,194],{"class":67},"rm",[61,196,197],{"class":89}," -rf",[61,199,200],{"class":71}," .vscode",[61,202,203],{"class":71}," .public",[61,205,206],{"class":71}," src\u002F{assets,components}\n",[61,208,209,212,215,219],{"class":63,"line":149},[61,210,211],{"class":89},"echo",[61,213,214],{"class":71}," \"\u003Ctemplate>\u003C\u002Ftemplate>\"",[61,216,218],{"class":217},"s8jYJ"," >",[61,220,221],{"class":71}," src\u002FApp.vue\n",[61,223,224,226,229,231],{"class":63,"line":161},[61,225,211],{"class":89},[61,227,228],{"class":71}," \"\"",[61,230,218],{"class":217},[61,232,233],{"class":71}," src\u002Fstyle.css\n",[10,235,236,237,240,241,240,244,247,248,251,252,255,256,247,259,119],{},"Remove the ",[47,238,239],{},".vscode"," folder, ",[47,242,243],{},"public",[47,245,246],{},"assets"," and ",[47,249,250],{},"components"," folders in ",[47,253,254],{},"src",", and the content of ",[47,257,258],{},"App.vue",[47,260,261],{},"style.css",[10,263,264],{},"Now, install the component library in the playground:",[51,266,268],{"className":53,"code":267,"filename":261,"language":56,"meta":57,"style":57},"pnpm add ..\u002F..\u002Fpackages\u002Fhuchet-vue\n",[47,269,270],{"__ignoreMap":57},[61,271,272,274,277],{"class":63,"line":64},[61,273,100],{"class":67},[61,275,276],{"class":71}," add",[61,278,279],{"class":71}," ..\u002F..\u002Fpackages\u002Fhuchet-vue\n",[10,281,282,283,286],{},"This command installs the component library by creating a symlink to it in ",[47,284,285],{},"node_modules",". Thus, any import made in the playground resolves to the component library in the monorepo, allowing real-time changes during development.",[10,288,289,290,293,294,296],{},"Start the watch script in the ",[47,291,292],{},"huchet-vue"," package folder and the dev script in the ",[47,295,129],{}," folder. Any change in the component library will reflect in the playground.",[39,298,300],{"id":299},"using-the-playground","Using the playground",[10,302,303],{},"With the component library installed in the playground, you can start using it.",[10,305,306,307,310,311,314],{},"In the ",[47,308,309],{},"src\u002FApp.vue"," file, import the ",[47,312,313],{},"Button"," component and use it:",[51,316,319],{"className":317,"code":318,"filename":309,"language":118,"meta":57,"style":57},"language-vue shiki shiki-themes github-light github-light github-dark","\u003Cscript lang=\"ts\" setup>\nimport { Button } from '@barbapapazes\u002Fhuchet-vue'\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Cdiv class=\"flex gap-6 p-6\">\n    \u003CButton label=\"Hello World\" \u002F>\n    \u003CButton label=\"Hello World\" variant=\"outline\" \u002F>\n  \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n",[47,320,321,344,358,367,374,384,403,422,445,455],{"__ignoreMap":57},[61,322,323,326,329,332,335,338,341],{"class":63,"line":64},[61,324,325],{"class":96},"\u003C",[61,327,328],{"class":142},"script",[61,330,331],{"class":67}," lang",[61,333,334],{"class":96},"=",[61,336,337],{"class":71},"\"ts\"",[61,339,340],{"class":67}," setup",[61,342,343],{"class":96},">\n",[61,345,346,349,352,355],{"class":63,"line":149},[61,347,348],{"class":217},"import",[61,350,351],{"class":96}," { Button } ",[61,353,354],{"class":217},"from",[61,356,357],{"class":71}," '@barbapapazes\u002Fhuchet-vue'\n",[61,359,360,363,365],{"class":63,"line":161},[61,361,362],{"class":96},"\u003C\u002F",[61,364,328],{"class":142},[61,366,343],{"class":96},[61,368,370],{"class":63,"line":369},4,[61,371,373],{"emptyLinePlaceholder":372},true,"\n",[61,375,377,379,382],{"class":63,"line":376},5,[61,378,325],{"class":96},[61,380,381],{"class":142},"template",[61,383,343],{"class":96},[61,385,387,390,393,396,398,401],{"class":63,"line":386},6,[61,388,389],{"class":96},"  \u003C",[61,391,392],{"class":142},"div",[61,394,395],{"class":67}," class",[61,397,334],{"class":96},[61,399,400],{"class":71},"\"flex gap-6 p-6\"",[61,402,343],{"class":96},[61,404,406,409,411,414,416,419],{"class":63,"line":405},7,[61,407,408],{"class":96},"    \u003C",[61,410,313],{"class":142},[61,412,413],{"class":67}," label",[61,415,334],{"class":96},[61,417,418],{"class":71},"\"Hello World\"",[61,420,421],{"class":96}," \u002F>\n",[61,423,425,427,429,431,433,435,438,440,443],{"class":63,"line":424},8,[61,426,408],{"class":96},[61,428,313],{"class":142},[61,430,413],{"class":67},[61,432,334],{"class":96},[61,434,418],{"class":71},[61,436,437],{"class":67}," variant",[61,439,334],{"class":96},[61,441,442],{"class":71},"\"outline\"",[61,444,421],{"class":96},[61,446,448,451,453],{"class":63,"line":447},9,[61,449,450],{"class":96},"  \u003C\u002F",[61,452,392],{"class":142},[61,454,343],{"class":96},[61,456,458,460,462],{"class":63,"line":457},10,[61,459,362],{"class":96},[61,461,381],{"class":142},[61,463,343],{"class":96},[10,465,466],{},"To view the result, start Vite in the playground:",[51,468,470],{"className":53,"code":469,"filename":55,"language":56,"meta":57,"style":57},"pnpm dev\n",[47,471,472],{"__ignoreMap":57},[61,473,474,476],{"class":63,"line":64},[61,475,100],{"class":67},[61,477,478],{"class":71}," dev\n",[10,480,481],{},"Then, start Vite in the component library:",[51,483,485],{"className":53,"code":484,"filename":55,"language":56,"meta":57,"style":57},"pnpm watch\n",[47,486,487],{"__ignoreMap":57},[61,488,489,491],{"class":63,"line":64},[61,490,100],{"class":67},[61,492,493],{"class":71}," watch\n",[495,496,499],"callout",{"color":497,"icon":498},"primary","i-ph-info-duotone",[10,500,501,502,505],{},"The more components your library has, the longer it will take to reflect changes in the playground. If it starts to slow down, consider directly importing the component from the library with a relative path or using a storybook like ",[14,503,504],{},"Histoire",", which we'll cover next.",[10,507,508],{},"In your browser, you should see two buttons, unstyled.",[510,511,512,517],"figure",{},[513,514],"img",{"alt":515,"src":516},"Two buttons, unstyled.","\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fcreating-a-playground-and-a-storybook-for-components\u002Ftwo-buttons-unstyled.png",[518,519,515],"figcaption",{},[39,521,523],{"id":522},"styling-the-playground","Styling the playground",[10,525,526],{},"Our components are unstyled. To reduce bundle size and allow user-side generation, we don't deliver CSS with the component library.",[495,528,530],{"color":529,"icon":498},"info",[10,531,532],{},"We could ship a Tailwind CSS configuration with the component library to ensure components are styled correctly in the playground.",[10,534,535,536,538],{},"We will use ",[14,537,36],{}," 4, even though it's not released yet, because it comes with a Vite plugin that simplifies usage and no more breaking changes are expected.",[51,540,542],{"className":53,"code":541,"filename":55,"language":56,"meta":57,"style":57},"pnpm i -D tailwindcss@next @tailwindcss\u002Fvite@next\n",[47,543,544],{"__ignoreMap":57},[61,545,546,548,551,554,557],{"class":63,"line":64},[61,547,100],{"class":67},[61,549,550],{"class":71}," i",[61,552,553],{"class":89}," -D",[61,555,556],{"class":71}," tailwindcss@next",[61,558,559],{"class":71}," @tailwindcss\u002Fvite@next\n",[10,561,562,563,566],{},"Then, register the Tailwind CSS plugin in the ",[47,564,565],{},"vite.config.ts"," file:",[51,568,572],{"className":569,"code":570,"filename":565,"language":571,"meta":57,"style":57},"language-ts shiki shiki-themes github-light github-light github-dark has-diff","import Tailwindcss from '@tailwindcss\u002Fvite'\nimport Vue from '@vitejs\u002Fplugin-vue'\nimport { defineConfig } from 'vite'\n\nexport default defineConfig({\n  plugins: [\n    Vue(),\n    Tailwindcss(), \u002F\u002F [!code ++]\n  ],\n})\n","ts",[47,573,574,586,598,610,614,628,633,641,650,655],{"__ignoreMap":57},[61,575,576,578,581,583],{"class":63,"line":64},[61,577,348],{"class":217},[61,579,580],{"class":96}," Tailwindcss ",[61,582,354],{"class":217},[61,584,585],{"class":71}," '@tailwindcss\u002Fvite'\n",[61,587,588,590,593,595],{"class":63,"line":149},[61,589,348],{"class":217},[61,591,592],{"class":96}," Vue ",[61,594,354],{"class":217},[61,596,597],{"class":71}," '@vitejs\u002Fplugin-vue'\n",[61,599,600,602,605,607],{"class":63,"line":161},[61,601,348],{"class":217},[61,603,604],{"class":96}," { defineConfig } ",[61,606,354],{"class":217},[61,608,609],{"class":71}," 'vite'\n",[61,611,612],{"class":63,"line":369},[61,613,373],{"emptyLinePlaceholder":372},[61,615,616,619,622,625],{"class":63,"line":376},[61,617,618],{"class":217},"export",[61,620,621],{"class":217}," default",[61,623,624],{"class":67}," defineConfig",[61,626,627],{"class":96},"({\n",[61,629,630],{"class":63,"line":386},[61,631,632],{"class":96},"  plugins: [\n",[61,634,635,638],{"class":63,"line":405},[61,636,637],{"class":67},"    Vue",[61,639,640],{"class":96},"(),\n",[61,642,644,647],{"class":643,"line":424},[63,159,160],[61,645,646],{"class":67},"    Tailwindcss",[61,648,649],{"class":96},"(), ",[61,651,652],{"class":63,"line":447},[61,653,654],{"class":96},"  ],\n",[61,656,657],{"class":63,"line":457},[61,658,659],{"class":96},"})\n",[10,661,306,662,665],{},[47,663,664],{},"src\u002Fstyle.css",", import Tailwind CSS styles:",[51,667,671],{"className":668,"code":669,"filename":664,"language":670,"meta":57,"style":57},"language-css shiki shiki-themes github-light github-light github-dark","@import \"tailwindcss\";\n","css",[47,672,673],{"__ignoreMap":57},[61,674,675,678,681],{"class":63,"line":64},[61,676,677],{"class":217},"@import",[61,679,680],{"class":71}," \"tailwindcss\"",[61,682,683],{"class":96},";\n",[10,685,686],{},"Automatically, the buttons are styled as expected.",[510,688,689,693],{},[513,690],{"alt":691,"src":692},"Two buttons, styled.","\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fcreating-a-playground-and-a-storybook-for-components\u002Ftwo-buttons-styled.png",[518,694,691],{},[39,696,698],{"id":697},"the-storybook-histoire","The Storybook Histoire",[10,700,701,702,705],{},"Sometimes a playground isn't enough. You need to document your components, visualize them in various scenarios, and isolate them to ensure issues stem from the component, not integration. This is where a ",[14,703,704],{},"storybook"," comes in.",[10,707,535,708,716,717,720],{},[709,710,714],"a",{"href":711,"rel":712},"https:\u002F\u002Fhistoire.dev\u002F",[713],"nofollow",[14,715,504],{},", a ",[14,718,719],{},"Storybook","-like tool that's lightweight, based on Vite, and optimized for Vue.js.",[722,723,725],"h3",{"id":724},"setting-up-histoire","Setting up Histoire",[10,727,728,729,731],{},"Setting up Histoire is simple, especially with ",[14,730,36],{}," 4.",[10,733,734],{},"First, create a new folder from the root of the project:",[51,736,738],{"className":53,"code":737,"filename":55,"language":56,"meta":57,"style":57},"mkdir .histoire && cd .histoire && echo '{\\n\"name\": \"huchet-vue-histoire\",\\n\"private\": true\\n}' > package.json\n",[47,739,740],{"__ignoreMap":57},[61,741,742,744,747,749,751,753,755,757,760,762],{"class":63,"line":64},[61,743,68],{"class":67},[61,745,746],{"class":71}," .histoire",[61,748,97],{"class":96},[61,750,90],{"class":89},[61,752,746],{"class":71},[61,754,97],{"class":96},[61,756,211],{"class":89},[61,758,759],{"class":71}," '{\\n\"name\": \"huchet-vue-histoire\",\\n\"private\": true\\n}'",[61,761,218],{"class":217},[61,763,764],{"class":71}," package.json\n",[495,766,767],{"color":529,"icon":498},[10,768,769,770,772],{},"I placed the Histoire folder at the project root instead of the ",[47,771,143],{}," folder because it's a development tool, not a publishable npm package.",[10,774,775],{},"Add the folder to the workspace:",[51,777,779],{"className":53,"code":778,"filename":55,"language":56,"meta":57,"style":57},"echo \"  - .histoire\" >> ..\u002Fpnpm-workspace.yaml\n",[47,780,781],{"__ignoreMap":57},[61,782,783,785,788,791],{"class":63,"line":64},[61,784,211],{"class":89},[61,786,787],{"class":71}," \"  - .histoire\"",[61,789,790],{"class":217}," >>",[61,792,793],{"class":71}," ..\u002Fpnpm-workspace.yaml\n",[10,795,796],{},"Install Histoire and Tailwind CSS:",[51,798,800],{"className":53,"code":799,"filename":55,"language":56,"meta":57,"style":57},"pnpm i -D histoire @histoire\u002Fplugin-vue @vitejs\u002Fplugin-vue vue tailwindcss@next @tailwindcss\u002Fvite@next\n",[47,801,802],{"__ignoreMap":57},[61,803,804,806,808,810,813,816,819,822,824],{"class":63,"line":64},[61,805,100],{"class":67},[61,807,550],{"class":71},[61,809,553],{"class":89},[61,811,812],{"class":71}," histoire",[61,814,815],{"class":71}," @histoire\u002Fplugin-vue",[61,817,818],{"class":71}," @vitejs\u002Fplugin-vue",[61,820,821],{"class":71}," vue",[61,823,556],{"class":71},[61,825,559],{"class":71},[495,827,828],{"color":529,"icon":498},[10,829,830],{},"We install Tailwind CSS now because we'll need it, as seen in the playground.",[10,832,833,834,837,838,841],{},"Histoire uses a configuration file named ",[47,835,836],{},"histoire.config.ts",", which we'll create in the ",[47,839,840],{},".histoire"," folder:",[51,843,845],{"className":53,"code":844,"filename":836,"language":56,"meta":57,"style":57},"touch histoire.config.ts\n",[47,846,847],{"__ignoreMap":57},[61,848,849,852],{"class":63,"line":64},[61,850,851],{"class":67},"touch",[61,853,854],{"class":71}," histoire.config.ts\n",[10,856,857],{},"The configuration includes multiple keys:",[859,860,861,867,877,886,892],"ul",{},[22,862,863,866],{},[47,864,865],{},"plugins",": Plugins for Histoire, such as the Histoire Vue plugin.",[22,868,869,872,873,876],{},[47,870,871],{},"storyMatch",": Files to match for creating stories, like the ",[47,874,875],{},"*.story.vue"," files.",[22,878,879,882,883,119],{},[47,880,881],{},"setupFile",": Setup file to use with Histoire, where we'll create a ",[47,884,885],{},"setup.ts",[22,887,888,891],{},[47,889,890],{},"theme",": Personalization options like title, logo, favicon for the Histoire interface.",[22,893,894,897],{},[47,895,896],{},"vite",": Vite configuration utilizing the Vue and Tailwind CSS plugins.",[51,899,902],{"className":900,"code":901,"filename":885,"language":571,"meta":57,"style":57},"language-ts shiki shiki-themes github-light github-light github-dark","import { resolve } from 'node:path'\nimport { HstVue } from '@histoire\u002Fplugin-vue'\nimport Tailwind from '@tailwindcss\u002Fvite'\nimport Vue from '@vitejs\u002Fplugin-vue'\nimport { defineConfig } from 'histoire'\n\nexport default defineConfig({\n  plugins: [HstVue()],\n\n  storyMatch: [\n    resolve(__dirname, '..\u002Fpackages\u002Fhuchet-vue\u002Fsrc\u002F**\u002F*.story.vue'),\n  ],\n\n  setupFile: resolve(__dirname, 'setup.ts'),\n\n  theme: {\n    title: 'Huchet Vue',\n  },\n\n  vite: {\n    plugins: [\n      Vue(),\n      Tailwind(),\n    ],\n    server: {\n      fs: {\n        allow: ['..'],\n      },\n    },\n  },\n})\n",[47,903,904,916,928,939,949,960,964,974,985,989,994,1009,1014,1019,1035,1040,1046,1058,1064,1069,1075,1081,1089,1097,1103,1109,1115,1127,1133,1139,1144],{"__ignoreMap":57},[61,905,906,908,911,913],{"class":63,"line":64},[61,907,348],{"class":217},[61,909,910],{"class":96}," { resolve } ",[61,912,354],{"class":217},[61,914,915],{"class":71}," 'node:path'\n",[61,917,918,920,923,925],{"class":63,"line":149},[61,919,348],{"class":217},[61,921,922],{"class":96}," { HstVue } ",[61,924,354],{"class":217},[61,926,927],{"class":71}," '@histoire\u002Fplugin-vue'\n",[61,929,930,932,935,937],{"class":63,"line":161},[61,931,348],{"class":217},[61,933,934],{"class":96}," Tailwind ",[61,936,354],{"class":217},[61,938,585],{"class":71},[61,940,941,943,945,947],{"class":63,"line":369},[61,942,348],{"class":217},[61,944,592],{"class":96},[61,946,354],{"class":217},[61,948,597],{"class":71},[61,950,951,953,955,957],{"class":63,"line":376},[61,952,348],{"class":217},[61,954,604],{"class":96},[61,956,354],{"class":217},[61,958,959],{"class":71}," 'histoire'\n",[61,961,962],{"class":63,"line":386},[61,963,373],{"emptyLinePlaceholder":372},[61,965,966,968,970,972],{"class":63,"line":405},[61,967,618],{"class":217},[61,969,621],{"class":217},[61,971,624],{"class":67},[61,973,627],{"class":96},[61,975,976,979,982],{"class":63,"line":424},[61,977,978],{"class":96},"  plugins: [",[61,980,981],{"class":67},"HstVue",[61,983,984],{"class":96},"()],\n",[61,986,987],{"class":63,"line":447},[61,988,373],{"emptyLinePlaceholder":372},[61,990,991],{"class":63,"line":457},[61,992,993],{"class":96},"  storyMatch: [\n",[61,995,997,1000,1003,1006],{"class":63,"line":996},11,[61,998,999],{"class":67},"    resolve",[61,1001,1002],{"class":96},"(__dirname, ",[61,1004,1005],{"class":71},"'..\u002Fpackages\u002Fhuchet-vue\u002Fsrc\u002F**\u002F*.story.vue'",[61,1007,1008],{"class":96},"),\n",[61,1010,1012],{"class":63,"line":1011},12,[61,1013,654],{"class":96},[61,1015,1017],{"class":63,"line":1016},13,[61,1018,373],{"emptyLinePlaceholder":372},[61,1020,1022,1025,1028,1030,1033],{"class":63,"line":1021},14,[61,1023,1024],{"class":96},"  setupFile: ",[61,1026,1027],{"class":67},"resolve",[61,1029,1002],{"class":96},[61,1031,1032],{"class":71},"'setup.ts'",[61,1034,1008],{"class":96},[61,1036,1038],{"class":63,"line":1037},15,[61,1039,373],{"emptyLinePlaceholder":372},[61,1041,1043],{"class":63,"line":1042},16,[61,1044,1045],{"class":96},"  theme: {\n",[61,1047,1049,1052,1055],{"class":63,"line":1048},17,[61,1050,1051],{"class":96},"    title: ",[61,1053,1054],{"class":71},"'Huchet Vue'",[61,1056,1057],{"class":96},",\n",[61,1059,1061],{"class":63,"line":1060},18,[61,1062,1063],{"class":96},"  },\n",[61,1065,1067],{"class":63,"line":1066},19,[61,1068,373],{"emptyLinePlaceholder":372},[61,1070,1072],{"class":63,"line":1071},20,[61,1073,1074],{"class":96},"  vite: {\n",[61,1076,1078],{"class":63,"line":1077},21,[61,1079,1080],{"class":96},"    plugins: [\n",[61,1082,1084,1087],{"class":63,"line":1083},22,[61,1085,1086],{"class":67},"      Vue",[61,1088,640],{"class":96},[61,1090,1092,1095],{"class":63,"line":1091},23,[61,1093,1094],{"class":67},"      Tailwind",[61,1096,640],{"class":96},[61,1098,1100],{"class":63,"line":1099},24,[61,1101,1102],{"class":96},"    ],\n",[61,1104,1106],{"class":63,"line":1105},25,[61,1107,1108],{"class":96},"    server: {\n",[61,1110,1112],{"class":63,"line":1111},26,[61,1113,1114],{"class":96},"      fs: {\n",[61,1116,1118,1121,1124],{"class":63,"line":1117},27,[61,1119,1120],{"class":96},"        allow: [",[61,1122,1123],{"class":71},"'..'",[61,1125,1126],{"class":96},"],\n",[61,1128,1130],{"class":63,"line":1129},28,[61,1131,1132],{"class":96},"      },\n",[61,1134,1136],{"class":63,"line":1135},29,[61,1137,1138],{"class":96},"    },\n",[61,1140,1142],{"class":63,"line":1141},30,[61,1143,1063],{"class":96},[61,1145,1147],{"class":63,"line":1146},31,[61,1148,659],{"class":96},[10,1150,1151,1152,1155,1156,1158,1159,1162],{},"Since the stories are in the component library, we must explicitly instruct Histoire to look for them in the ",[47,1153,1154],{},"packages\u002Fhuchet-vue\u002Fsrc"," folder using the ",[47,1157,871],{}," key. Meanwhile, we permit the Histoire server to access the parent folder via the ",[47,1160,1161],{},"server.fs.allow"," key, preventing file accessibility issues.",[10,1164,1165,1166,1168],{},"To implement Tailwind CSS in Histoire, import the CSS in the ",[47,1167,885],{}," file, similar to the playground:",[51,1170,1172],{"className":53,"code":1171,"filename":885,"language":56,"meta":57,"style":57},"touch setup.ts style.css\necho \"import '.\u002Fstyle.css';\" > setup.ts\necho \"@import 'tailwindcss';\" > style.css\n",[47,1173,1174,1184,1196],{"__ignoreMap":57},[61,1175,1176,1178,1181],{"class":63,"line":64},[61,1177,851],{"class":67},[61,1179,1180],{"class":71}," setup.ts",[61,1182,1183],{"class":71}," style.css\n",[61,1185,1186,1188,1191,1193],{"class":63,"line":149},[61,1187,211],{"class":89},[61,1189,1190],{"class":71}," \"import '.\u002Fstyle.css';\"",[61,1192,218],{"class":217},[61,1194,1195],{"class":71}," setup.ts\n",[61,1197,1198,1200,1203,1205],{"class":63,"line":161},[61,1199,211],{"class":89},[61,1201,1202],{"class":71}," \"@import 'tailwindcss';\"",[61,1204,218],{"class":217},[61,1206,1183],{"class":71},[495,1208,1209],{"color":529,"icon":498},[10,1210,1211,1212,1214],{},"The ",[47,1213,885],{}," file is executed on Histoire's startup and is an ideal place for personalization or global styles.",[10,1216,1217,1218,1221],{},"To begin with Histoire, add three scripts to the ",[47,1219,1220],{},"package.json",":",[51,1223,1227],{"className":1224,"code":1225,"filename":1220,"language":1226,"meta":57,"style":57},"language-json shiki shiki-themes github-light github-light github-dark","{\n  \"scripts\": {\n    \"dev\": \"histoire dev\",\n    \"build\": \"histoire build\",\n    \"serve\": \"histoire serve\"\n  }\n}\n","json",[47,1228,1229,1234,1242,1255,1267,1277,1282],{"__ignoreMap":57},[61,1230,1231],{"class":63,"line":64},[61,1232,1233],{"class":96},"{\n",[61,1235,1236,1239],{"class":63,"line":149},[61,1237,1238],{"class":89},"  \"scripts\"",[61,1240,1241],{"class":96},": {\n",[61,1243,1244,1247,1250,1253],{"class":63,"line":161},[61,1245,1246],{"class":89},"    \"dev\"",[61,1248,1249],{"class":96},": ",[61,1251,1252],{"class":71},"\"histoire dev\"",[61,1254,1057],{"class":96},[61,1256,1257,1260,1262,1265],{"class":63,"line":369},[61,1258,1259],{"class":89},"    \"build\"",[61,1261,1249],{"class":96},[61,1263,1264],{"class":71},"\"histoire build\"",[61,1266,1057],{"class":96},[61,1268,1269,1272,1274],{"class":63,"line":376},[61,1270,1271],{"class":89},"    \"serve\"",[61,1273,1249],{"class":96},[61,1275,1276],{"class":71},"\"histoire serve\"\n",[61,1278,1279],{"class":63,"line":386},[61,1280,1281],{"class":96},"  }\n",[61,1283,1284],{"class":63,"line":405},[61,1285,1286],{"class":96},"}\n",[10,1288,1289],{},"Now, we can start Histoire:",[51,1291,1292],{"className":53,"code":469,"filename":55,"language":56,"meta":57,"style":57},[47,1293,1294],{"__ignoreMap":57},[61,1295,1296,1298],{"class":63,"line":64},[61,1297,100],{"class":67},[61,1299,478],{"class":71},[510,1301,1302,1306],{},[513,1303],{"alt":1304,"src":1305},"Histoire running.","\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fcreating-a-playground-and-a-storybook-for-components\u002Fhistoire-running.png",[518,1307,1304],{},[722,1309,1311],{"id":1310},"creating-a-story","Creating a story",[10,1313,1314,1315,1318,1319,1221],{},"Returning to ",[47,1316,1317],{},"packages\u002Fhuchet-vue",", we can create our first story file, ",[47,1320,1321],{},"Button\u002FButton.story.vue",[51,1323,1325],{"className":53,"code":1324,"filename":1321,"language":56,"meta":57,"style":57},"touch src\u002FButton\u002FButton.story.vue\n",[47,1326,1327],{"__ignoreMap":57},[61,1328,1329,1331],{"class":63,"line":64},[61,1330,851],{"class":67},[61,1332,1333],{"class":71}," src\u002FButton\u002FButton.story.vue\n",[10,1335,1336],{},"Histoire offers predefined components for crafting a story with variants.",[19,1338,1339,1345],{},[22,1340,1341,1344],{},[47,1342,1343],{},"Story",": The main component for creating a story.",[22,1346,1347,1350],{},[47,1348,1349],{},"Variant",": A component to create a variant of a component within the story.",[10,1352,1353,1354,1357,1358,247,1361,119],{},"In our scenario, we create a story in ",[47,1355,1356],{},"Button.story.vue"," with two variants: ",[47,1359,1360],{},"solid",[47,1362,1363],{},"outline",[51,1365,1367],{"className":317,"code":1366,"filename":1356,"language":118,"meta":57,"style":57},"\u003Cscript lang=\"ts\" setup>\nimport { logEvent } from 'histoire\u002Fclient'\nimport Button from '.\u002FButton.vue'\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003CStory>\n    \u003CVariant title=\"Solid\">\n      \u003CButton variant=\"solid\" label=\"Hello World\" @click=\"logEvent('Click', $event)\" \u002F>\n    \u003C\u002FVariant>\n    \u003CVariant title=\"Outline\">\n      \u003CButton variant=\"outline\" label=\"Hello World\" @click=\"logEvent('Click', $event)\" \u002F>\n    \u003C\u002FVariant>\n  \u003C\u002FStory>\n\u003C\u002Ftemplate>\n",[47,1368,1369,1385,1397,1409,1417,1421,1429,1437,1453,1500,1509,1524,1562,1570,1578],{"__ignoreMap":57},[61,1370,1371,1373,1375,1377,1379,1381,1383],{"class":63,"line":64},[61,1372,325],{"class":96},[61,1374,328],{"class":142},[61,1376,331],{"class":67},[61,1378,334],{"class":96},[61,1380,337],{"class":71},[61,1382,340],{"class":67},[61,1384,343],{"class":96},[61,1386,1387,1389,1392,1394],{"class":63,"line":149},[61,1388,348],{"class":217},[61,1390,1391],{"class":96}," { logEvent } ",[61,1393,354],{"class":217},[61,1395,1396],{"class":71}," 'histoire\u002Fclient'\n",[61,1398,1399,1401,1404,1406],{"class":63,"line":161},[61,1400,348],{"class":217},[61,1402,1403],{"class":96}," Button ",[61,1405,354],{"class":217},[61,1407,1408],{"class":71}," '.\u002FButton.vue'\n",[61,1410,1411,1413,1415],{"class":63,"line":369},[61,1412,362],{"class":96},[61,1414,328],{"class":142},[61,1416,343],{"class":96},[61,1418,1419],{"class":63,"line":376},[61,1420,373],{"emptyLinePlaceholder":372},[61,1422,1423,1425,1427],{"class":63,"line":386},[61,1424,325],{"class":96},[61,1426,381],{"class":142},[61,1428,343],{"class":96},[61,1430,1431,1433,1435],{"class":63,"line":405},[61,1432,389],{"class":96},[61,1434,1343],{"class":142},[61,1436,343],{"class":96},[61,1438,1439,1441,1443,1446,1448,1451],{"class":63,"line":424},[61,1440,408],{"class":96},[61,1442,1349],{"class":142},[61,1444,1445],{"class":67}," title",[61,1447,334],{"class":96},[61,1449,1450],{"class":71},"\"Solid\"",[61,1452,343],{"class":96},[61,1454,1455,1458,1460,1462,1464,1467,1469,1471,1473,1476,1479,1481,1484,1487,1490,1493,1496,1498],{"class":63,"line":447},[61,1456,1457],{"class":96},"      \u003C",[61,1459,313],{"class":142},[61,1461,437],{"class":67},[61,1463,334],{"class":96},[61,1465,1466],{"class":71},"\"solid\"",[61,1468,413],{"class":67},[61,1470,334],{"class":96},[61,1472,418],{"class":71},[61,1474,1475],{"class":96}," @",[61,1477,1478],{"class":67},"click",[61,1480,334],{"class":96},[61,1482,1483],{"class":71},"\"",[61,1485,1486],{"class":67},"logEvent",[61,1488,1489],{"class":96},"(",[61,1491,1492],{"class":71},"'Click'",[61,1494,1495],{"class":96},", $event)",[61,1497,1483],{"class":71},[61,1499,421],{"class":96},[61,1501,1502,1505,1507],{"class":63,"line":457},[61,1503,1504],{"class":96},"    \u003C\u002F",[61,1506,1349],{"class":142},[61,1508,343],{"class":96},[61,1510,1511,1513,1515,1517,1519,1522],{"class":63,"line":996},[61,1512,408],{"class":96},[61,1514,1349],{"class":142},[61,1516,1445],{"class":67},[61,1518,334],{"class":96},[61,1520,1521],{"class":71},"\"Outline\"",[61,1523,343],{"class":96},[61,1525,1526,1528,1530,1532,1534,1536,1538,1540,1542,1544,1546,1548,1550,1552,1554,1556,1558,1560],{"class":63,"line":1011},[61,1527,1457],{"class":96},[61,1529,313],{"class":142},[61,1531,437],{"class":67},[61,1533,334],{"class":96},[61,1535,442],{"class":71},[61,1537,413],{"class":67},[61,1539,334],{"class":96},[61,1541,418],{"class":71},[61,1543,1475],{"class":96},[61,1545,1478],{"class":67},[61,1547,334],{"class":96},[61,1549,1483],{"class":71},[61,1551,1486],{"class":67},[61,1553,1489],{"class":96},[61,1555,1492],{"class":71},[61,1557,1495],{"class":96},[61,1559,1483],{"class":71},[61,1561,421],{"class":96},[61,1563,1564,1566,1568],{"class":63,"line":1016},[61,1565,1504],{"class":96},[61,1567,1349],{"class":142},[61,1569,343],{"class":96},[61,1571,1572,1574,1576],{"class":63,"line":1021},[61,1573,450],{"class":96},[61,1575,1343],{"class":142},[61,1577,343],{"class":96},[61,1579,1580,1582,1584],{"class":63,"line":1037},[61,1581,362],{"class":96},[61,1583,381],{"class":142},[61,1585,343],{"class":96},[495,1587,1588],{"color":529,"icon":498},[10,1589,1211,1590,1592],{},[47,1591,1486],{}," function logs events in the interface, aiding developers in understanding the component's output.",[10,1594,1595],{},"And it works!",[510,1597,1598,1602],{},[513,1599],{"alt":1600,"src":1601},"Histoire with the Button component.","\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fcreating-a-playground-and-a-storybook-for-components\u002Fhistoire-button-component-styled.png",[518,1603,1600],{},[10,1605,1606,1607,247,1609,1611],{},"However, a major issue persists: the ",[47,1608,1343],{},[47,1610,1349],{}," components are not recognized by our editor.",[722,1613,1615],{"id":1614},"adding-histoire-types","Adding Histoire types",[10,1617,1618],{},"Fortunately, we can resolve this issue easily as Histoire provides the necessary tools.",[10,1620,1621,1622,841],{},"Histoire introduces a new TypeScript context within our project, so we need to create a new TSConfig file in the ",[47,1623,1317],{},[51,1625,1627],{"className":53,"code":1626,"filename":55,"language":56,"meta":57,"style":57},"touch tsconfig.story.json\n",[47,1628,1629],{"__ignoreMap":57},[61,1630,1631,1633],{"class":63,"line":64},[61,1632,851],{"class":67},[61,1634,1635],{"class":71}," tsconfig.story.json\n",[10,1637,1638,1639,1642,1643,1646,1647,566],{},"This file extends ",[47,1640,1641],{},"tsconfig.app.json"," but captures only the ",[47,1644,1645],{},"story.vue"," files and a new ",[47,1648,1649],{},"histoire.d.ts",[51,1651,1653],{"className":1224,"code":1652,"filename":1649,"language":1226,"meta":57,"style":57},"{\n  \"extends\": \".\u002Ftsconfig.app.json\",\n  \"compilerOptions\": {\n    \"moduleResolution\": \"node\"\n  },\n  \"include\": [\n    \"histoire.d.ts\",\n    \"src\u002F**\u002F*.story.vue\"\n  ],\n  \"exclude\": []\n}\n",[47,1654,1655,1659,1671,1678,1688,1692,1700,1707,1712,1716,1724],{"__ignoreMap":57},[61,1656,1657],{"class":63,"line":64},[61,1658,1233],{"class":96},[61,1660,1661,1664,1666,1669],{"class":63,"line":149},[61,1662,1663],{"class":89},"  \"extends\"",[61,1665,1249],{"class":96},[61,1667,1668],{"class":71},"\".\u002Ftsconfig.app.json\"",[61,1670,1057],{"class":96},[61,1672,1673,1676],{"class":63,"line":161},[61,1674,1675],{"class":89},"  \"compilerOptions\"",[61,1677,1241],{"class":96},[61,1679,1680,1683,1685],{"class":63,"line":369},[61,1681,1682],{"class":89},"    \"moduleResolution\"",[61,1684,1249],{"class":96},[61,1686,1687],{"class":71},"\"node\"\n",[61,1689,1690],{"class":63,"line":376},[61,1691,1063],{"class":96},[61,1693,1694,1697],{"class":63,"line":386},[61,1695,1696],{"class":89},"  \"include\"",[61,1698,1699],{"class":96},": [\n",[61,1701,1702,1705],{"class":63,"line":405},[61,1703,1704],{"class":71},"    \"histoire.d.ts\"",[61,1706,1057],{"class":96},[61,1708,1709],{"class":63,"line":424},[61,1710,1711],{"class":71},"    \"src\u002F**\u002F*.story.vue\"\n",[61,1713,1714],{"class":63,"line":447},[61,1715,654],{"class":96},[61,1717,1718,1721],{"class":63,"line":457},[61,1719,1720],{"class":89},"  \"exclude\"",[61,1722,1723],{"class":96},": []\n",[61,1725,1726],{"class":63,"line":996},[61,1727,1286],{"class":96},[495,1729,1730],{"color":529,"icon":498},[10,1731,1211,1732,1735,1736,1739,1740,1743,1744,1747,1748,1751,1752,1755,1756,119],{},[47,1733,1734],{},"moduleResolution"," option is vital for accurate module resolution. The ",[47,1737,1738],{},"@vue\u002Ftsconfig"," package uses ",[47,1741,1742],{},"Bundler",", but we need ",[47,1745,1746],{},"Node"," for our use case. Ensure ",[47,1749,1750],{},"\"exclude\": []"," overwrites the ",[47,1753,1754],{},"exclude"," option in ",[47,1757,1641],{},[10,1759,1760,1761,566],{},"Create the ",[47,1762,1649],{},[51,1764,1766],{"className":53,"code":1765,"filename":1649,"language":56,"meta":57,"style":57},"touch histoire.d.ts\n",[47,1767,1768],{"__ignoreMap":57},[61,1769,1770,1772],{"class":63,"line":64},[61,1771,851],{"class":67},[61,1773,1774],{"class":71}," histoire.d.ts\n",[10,1776,1777],{},"Reference Histoire's types in this file:",[51,1779,1782],{"className":900,"code":1780,"filename":1781,"language":571,"meta":57,"style":57},"\u002F\u002F\u002F \u003Creference types=\"@histoire\u002Fplugin-vue\u002Fcomponents\" \u002F>\n","Example",[47,1783,1784],{"__ignoreMap":57},[61,1785,1786,1790,1793,1796,1798,1801],{"class":63,"line":64},[61,1787,1789],{"class":1788},"sCsY4","\u002F\u002F\u002F \u003C",[61,1791,1792],{"class":142},"reference",[61,1794,1795],{"class":67}," types",[61,1797,334],{"class":217},[61,1799,1800],{"class":71},"\"@histoire\u002Fplugin-vue\u002Fcomponents\"",[61,1802,421],{"class":1788},[10,1804,1805,1806,1221],{},"Register the new TSConfig in the ",[47,1807,1808],{},"tsconfig.json",[51,1810,1813],{"className":1811,"code":1812,"filename":1808,"language":1226,"meta":57,"style":57},"language-json shiki shiki-themes github-light github-light github-dark has-diff","{\n  \"files\": [],\n  \"references\": [\n    {\n      \"path\": \".\u002Ftsconfig.app.json\"\n    },\n    {\n      \"path\": \".\u002Ftsconfig.node.json\"\n    },\n    {\n      \"path\": \".\u002Ftsconfig.story.json\" \u002F\u002F [!code ++]\n    }\n  ]\n}\n",[47,1814,1815,1819,1827,1834,1839,1849,1853,1857,1866,1870,1874,1884,1889,1894],{"__ignoreMap":57},[61,1816,1817],{"class":63,"line":64},[61,1818,1233],{"class":96},[61,1820,1821,1824],{"class":63,"line":149},[61,1822,1823],{"class":89},"  \"files\"",[61,1825,1826],{"class":96},": [],\n",[61,1828,1829,1832],{"class":63,"line":161},[61,1830,1831],{"class":89},"  \"references\"",[61,1833,1699],{"class":96},[61,1835,1836],{"class":63,"line":369},[61,1837,1838],{"class":96},"    {\n",[61,1840,1841,1844,1846],{"class":63,"line":376},[61,1842,1843],{"class":89},"      \"path\"",[61,1845,1249],{"class":96},[61,1847,1848],{"class":71},"\".\u002Ftsconfig.app.json\"\n",[61,1850,1851],{"class":63,"line":386},[61,1852,1138],{"class":96},[61,1854,1855],{"class":63,"line":405},[61,1856,1838],{"class":96},[61,1858,1859,1861,1863],{"class":63,"line":424},[61,1860,1843],{"class":89},[61,1862,1249],{"class":96},[61,1864,1865],{"class":71},"\".\u002Ftsconfig.node.json\"\n",[61,1867,1868],{"class":63,"line":447},[61,1869,1138],{"class":96},[61,1871,1872],{"class":63,"line":457},[61,1873,1838],{"class":96},[61,1875,1877,1879,1881],{"class":1876,"line":996},[63,159,160],[61,1878,1843],{"class":89},[61,1880,1249],{"class":96},[61,1882,1883],{"class":71},"\".\u002Ftsconfig.story.json\"",[61,1885,1886],{"class":63,"line":1011},[61,1887,1888],{"class":96},"    }\n",[61,1890,1891],{"class":63,"line":1016},[61,1892,1893],{"class":96},"  ]\n",[61,1895,1896],{"class":63,"line":1021},[61,1897,1286],{"class":96},[10,1899,1900,1901,1903,1904,1906],{},"Update ",[47,1902,1641],{}," with an ",[47,1905,1754],{}," option to avoid overlapping TSConfig capture:",[51,1908,1910],{"className":1224,"code":1909,"filename":1641,"language":1226,"meta":57,"style":57},"{\n  \"extends\": \"@vue\u002Ftsconfig\u002Ftsconfig.dom.json\",\n  \"include\": [\n    \"src\u002F**\u002F*.ts\",\n    \"src\u002F**\u002F*.vue\"\n  ],\n  \"exclude\": [\n    \"src\u002F**\u002F*.story.vue\"\n  ]\n}\n",[47,1911,1912,1916,1927,1933,1940,1945,1949,1955,1959,1963],{"__ignoreMap":57},[61,1913,1914],{"class":63,"line":64},[61,1915,1233],{"class":96},[61,1917,1918,1920,1922,1925],{"class":63,"line":149},[61,1919,1663],{"class":89},[61,1921,1249],{"class":96},[61,1923,1924],{"class":71},"\"@vue\u002Ftsconfig\u002Ftsconfig.dom.json\"",[61,1926,1057],{"class":96},[61,1928,1929,1931],{"class":63,"line":161},[61,1930,1696],{"class":89},[61,1932,1699],{"class":96},[61,1934,1935,1938],{"class":63,"line":369},[61,1936,1937],{"class":71},"    \"src\u002F**\u002F*.ts\"",[61,1939,1057],{"class":96},[61,1941,1942],{"class":63,"line":376},[61,1943,1944],{"class":71},"    \"src\u002F**\u002F*.vue\"\n",[61,1946,1947],{"class":63,"line":386},[61,1948,654],{"class":96},[61,1950,1951,1953],{"class":63,"line":405},[61,1952,1720],{"class":89},[61,1954,1699],{"class":96},[61,1956,1957],{"class":63,"line":424},[61,1958,1711],{"class":71},[61,1960,1961],{"class":63,"line":447},[61,1962,1893],{"class":96},[61,1964,1965],{"class":63,"line":457},[61,1966,1286],{"class":96},[495,1968,1969],{"color":529,"icon":498},[10,1970,1971],{},"Overlapping TSConfig captures can lead to unexpected behavior and numerous issues. Ensure clear boundaries between TSConfigs to avoid conflicts.",[10,1973,1974],{},"In the next article, we will enhance integration with the Vue.js ecosystem by creating a resolver for Unplugin Vue Component and a Nuxt module.",[1976,1977,1978],"style",{},"html pre.shiki code .snPdu, html code.shiki .snPdu{--shiki-light:#6F42C1;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sIIMD, html code.shiki .sIIMD{--shiki-light:#032F62;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .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 .sBjJW, html code.shiki .sBjJW{--shiki-light:#005CC5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}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 .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}",{"title":57,"searchDepth":149,"depth":149,"links":1980},[1981,1982,1983,1984],{"id":41,"depth":149,"text":42},{"id":299,"depth":149,"text":300},{"id":522,"depth":149,"text":523},{"id":697,"depth":149,"text":698,"children":1985},[1986,1987,1988],{"id":724,"depth":161,"text":725},{"id":1310,"depth":161,"text":1311},{"id":1614,"depth":161,"text":1615},"53bbc0ae-a7b8-49d3-8ae6-73b585c43efc","2024-11-24","Learn how to create a playground and use Histoire to visualize and document your components in both isolated and combined scenarios.","md",null,{},"\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fcreating-a-playground-and-a-storybook-for-components","---\ncontentId: 53bbc0ae-a7b8-49d3-8ae6-73b585c43efc\npart: 6\ntitle: \"Creating a Playground and a Storybook for Components\"\ndescription: \"Learn how to create a playground and use Histoire to visualize and document your components in both isolated and combined scenarios.\"\ndate: 2024-11-24\nseriesSlug: the-complete-guide-to-building-a-vue-js-component-library\n---\n\nWe have components and tests, but until now, we've been unable to see them in action. It's time to create a **playground** for two key reasons:\n\n1. **Testing**: We need to test our components in a real environment to ensure they work as expected. Writing a page with all components, their props, and slots helps create the best API and implement it efficiently. This approach minimizes frequent refactoring by providing a comprehensive view of the components.\n2. **Visualizing**: Visualizing components is essential. While **Tailwind CSS** simplifies styling, it's impossible to fully grasp a component through code, especially complex ones with numerous variants or slots. A playground allows us to see components in action and test them in various scenarios.\n\n## Setting up the playground\n\nFirst, create a new folder named `playground` at the root of your project.\n\n```bash [terminal]\nmkdir playground\n```\n\nThen, create a new **Vite** project in this folder, which will depend on our component library. Being in a monorepo simplifies this process.\n\n```bash [terminal]\ncd playground && pnpm create vite --template vue-ts\n```\n\nName this project `vue`.\n\nBefore installing dependencies, update the `pnpm-workspace.yaml` to include the `playground\u002Fvue` package. This allows the playground to access the component library.\n\n```yaml [pnpm-workspace.yaml]\npackages:\n  - 'packages\u002F*'\n  - 'playground\u002F*' # [!code ++]\n```\n\nInstall the playground dependencies:\n\n```bash [terminal]\npnpm install\n```\n\nIn this Vue.js playground, remove unnecessary files, folders, and content:\n\n```bash [terminal]\nrm -rf .vscode .public src\u002F{assets,components}\necho \"\u003Ctemplate>\u003C\u002Ftemplate>\" > src\u002FApp.vue\necho \"\" > src\u002Fstyle.css\n```\n\nRemove the `.vscode` folder, `public` folder, `assets` and `components` folders in `src`, and the content of `App.vue` and `style.css`.\n\nNow, install the component library in the playground:\n\n```bash [style.css]\npnpm add ..\u002F..\u002Fpackages\u002Fhuchet-vue\n```\n\nThis command installs the component library by creating a symlink to it in `node_modules`. Thus, any import made in the playground resolves to the component library in the monorepo, allowing real-time changes during development.\n\nStart the watch script in the `huchet-vue` package folder and the dev script in the `playground\u002Fvue` folder. Any change in the component library will reflect in the playground.\n\n## Using the playground\n\nWith the component library installed in the playground, you can start using it.\n\nIn the `src\u002FApp.vue` file, import the `Button` component and use it:\n\n```vue [src\u002FApp.vue]\n\u003Cscript lang=\"ts\" setup>\nimport { Button } from '@barbapapazes\u002Fhuchet-vue'\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003Cdiv class=\"flex gap-6 p-6\">\n    \u003CButton label=\"Hello World\" \u002F>\n    \u003CButton label=\"Hello World\" variant=\"outline\" \u002F>\n  \u003C\u002Fdiv>\n\u003C\u002Ftemplate>\n```\n\nTo view the result, start Vite in the playground:\n\n```bash [terminal]\npnpm dev\n```\n\nThen, start Vite in the component library:\n\n```bash [terminal]\npnpm watch\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"primary\"}\nThe more components your library has, the longer it will take to reflect changes in the playground. If it starts to slow down, consider directly importing the component from the library with a relative path or using a storybook like **Histoire**, which we'll cover next.\n::\n\nIn your browser, you should see two buttons, unstyled.\n\n![Two buttons, unstyled.](\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fcreating-a-playground-and-a-storybook-for-components\u002Ftwo-buttons-unstyled.png)\n\n## Styling the playground\n\nOur components are unstyled. To reduce bundle size and allow user-side generation, we don't deliver CSS with the component library.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nWe could ship a Tailwind CSS configuration with the component library to ensure components are styled correctly in the playground.\n::\n\nWe will use **Tailwind CSS** 4, even though it's not released yet, because it comes with a Vite plugin that simplifies usage and no more breaking changes are expected.\n\n```bash [terminal]\npnpm i -D tailwindcss@next @tailwindcss\u002Fvite@next\n```\n\nThen, register the Tailwind CSS plugin in the `vite.config.ts` file:\n\n```ts [vite.config.ts]\nimport Tailwindcss from '@tailwindcss\u002Fvite'\nimport Vue from '@vitejs\u002Fplugin-vue'\nimport { defineConfig } from 'vite'\n\nexport default defineConfig({\n  plugins: [\n    Vue(),\n    Tailwindcss(), \u002F\u002F [!code ++]\n  ],\n})\n```\n\nIn the `src\u002Fstyle.css`, import Tailwind CSS styles:\n\n```css [src\u002Fstyle.css]\n@import \"tailwindcss\";\n```\n\nAutomatically, the buttons are styled as expected.\n\n![Two buttons, styled.](\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fcreating-a-playground-and-a-storybook-for-components\u002Ftwo-buttons-styled.png)\n\n## The Storybook Histoire\n\nSometimes a playground isn't enough. You need to document your components, visualize them in various scenarios, and isolate them to ensure issues stem from the component, not integration. This is where a **storybook** comes in.\n\nWe will use [**Histoire**](https:\u002F\u002Fhistoire.dev\u002F), a **Storybook**-like tool that's lightweight, based on Vite, and optimized for Vue.js.\n\n### Setting up Histoire\n\nSetting up Histoire is simple, especially with **Tailwind CSS** 4.\n\nFirst, create a new folder from the root of the project:\n\n```bash [terminal]\nmkdir .histoire && cd .histoire && echo '{\\n\"name\": \"huchet-vue-histoire\",\\n\"private\": true\\n}' > package.json\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nI placed the Histoire folder at the project root instead of the `packages` folder because it's a development tool, not a publishable npm package.\n::\n\nAdd the folder to the workspace:\n\n```bash [terminal]\necho \"  - .histoire\" >> ..\u002Fpnpm-workspace.yaml\n```\n\nInstall Histoire and Tailwind CSS:\n\n```bash [terminal]\npnpm i -D histoire @histoire\u002Fplugin-vue @vitejs\u002Fplugin-vue vue tailwindcss@next @tailwindcss\u002Fvite@next\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nWe install Tailwind CSS now because we'll need it, as seen in the playground.\n::\n\nHistoire uses a configuration file named `histoire.config.ts`, which we'll create in the `.histoire` folder:\n\n```bash [histoire.config.ts]\ntouch histoire.config.ts\n```\n\nThe configuration includes multiple keys:\n\n- `plugins`: Plugins for Histoire, such as the Histoire Vue plugin.\n- `storyMatch`: Files to match for creating stories, like the `*.story.vue` files.\n- `setupFile`: Setup file to use with Histoire, where we'll create a `setup.ts`.\n- `theme`: Personalization options like title, logo, favicon for the Histoire interface.\n- `vite`: Vite configuration utilizing the Vue and Tailwind CSS plugins.\n\n```ts [setup.ts]\nimport { resolve } from 'node:path'\nimport { HstVue } from '@histoire\u002Fplugin-vue'\nimport Tailwind from '@tailwindcss\u002Fvite'\nimport Vue from '@vitejs\u002Fplugin-vue'\nimport { defineConfig } from 'histoire'\n\nexport default defineConfig({\n  plugins: [HstVue()],\n\n  storyMatch: [\n    resolve(__dirname, '..\u002Fpackages\u002Fhuchet-vue\u002Fsrc\u002F**\u002F*.story.vue'),\n  ],\n\n  setupFile: resolve(__dirname, 'setup.ts'),\n\n  theme: {\n    title: 'Huchet Vue',\n  },\n\n  vite: {\n    plugins: [\n      Vue(),\n      Tailwind(),\n    ],\n    server: {\n      fs: {\n        allow: ['..'],\n      },\n    },\n  },\n})\n```\n\nSince the stories are in the component library, we must explicitly instruct Histoire to look for them in the `packages\u002Fhuchet-vue\u002Fsrc` folder using the `storyMatch` key. Meanwhile, we permit the Histoire server to access the parent folder via the `server.fs.allow` key, preventing file accessibility issues.\n\nTo implement Tailwind CSS in Histoire, import the CSS in the `setup.ts` file, similar to the playground:\n\n```bash [setup.ts]\ntouch setup.ts style.css\necho \"import '.\u002Fstyle.css';\" > setup.ts\necho \"@import 'tailwindcss';\" > style.css\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nThe `setup.ts` file is executed on Histoire's startup and is an ideal place for personalization or global styles.\n::\n\nTo begin with Histoire, add three scripts to the `package.json`:\n\n```json [package.json]\n{\n  \"scripts\": {\n    \"dev\": \"histoire dev\",\n    \"build\": \"histoire build\",\n    \"serve\": \"histoire serve\"\n  }\n}\n```\n\nNow, we can start Histoire:\n\n```bash [terminal]\npnpm dev\n```\n\n![Histoire running.](\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fcreating-a-playground-and-a-storybook-for-components\u002Fhistoire-running.png)\n\n### Creating a story\n\nReturning to `packages\u002Fhuchet-vue`, we can create our first story file, `Button\u002FButton.story.vue`:\n\n```bash [Button\u002FButton.story.vue]\ntouch src\u002FButton\u002FButton.story.vue\n```\n\nHistoire offers predefined components for crafting a story with variants.\n\n1. `Story`: The main component for creating a story.\n2. `Variant`: A component to create a variant of a component within the story.\n\nIn our scenario, we create a story in `Button.story.vue` with two variants: `solid` and `outline`.\n\n```vue [Button.story.vue]\n\u003Cscript lang=\"ts\" setup>\nimport { logEvent } from 'histoire\u002Fclient'\nimport Button from '.\u002FButton.vue'\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003CStory>\n    \u003CVariant title=\"Solid\">\n      \u003CButton variant=\"solid\" label=\"Hello World\" @click=\"logEvent('Click', $event)\" \u002F>\n    \u003C\u002FVariant>\n    \u003CVariant title=\"Outline\">\n      \u003CButton variant=\"outline\" label=\"Hello World\" @click=\"logEvent('Click', $event)\" \u002F>\n    \u003C\u002FVariant>\n  \u003C\u002FStory>\n\u003C\u002Ftemplate>\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nThe `logEvent` function logs events in the interface, aiding developers in understanding the component's output.\n::\n\nAnd it works!\n\n![Histoire with the Button component.](\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fcreating-a-playground-and-a-storybook-for-components\u002Fhistoire-button-component-styled.png)\n\nHowever, a major issue persists: the `Story` and `Variant` components are not recognized by our editor.\n\n### Adding Histoire types\n\nFortunately, we can resolve this issue easily as Histoire provides the necessary tools.\n\nHistoire introduces a new TypeScript context within our project, so we need to create a new TSConfig file in the `packages\u002Fhuchet-vue` folder:\n\n```bash [terminal]\ntouch tsconfig.story.json\n```\n\nThis file extends `tsconfig.app.json` but captures only the `story.vue` files and a new `histoire.d.ts` file:\n\n```json [histoire.d.ts]\n{\n  \"extends\": \".\u002Ftsconfig.app.json\",\n  \"compilerOptions\": {\n    \"moduleResolution\": \"node\"\n  },\n  \"include\": [\n    \"histoire.d.ts\",\n    \"src\u002F**\u002F*.story.vue\"\n  ],\n  \"exclude\": []\n}\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nThe `moduleResolution` option is vital for accurate module resolution. The `@vue\u002Ftsconfig` package uses `Bundler`, but we need `Node` for our use case. Ensure `\"exclude\": []` overwrites the `exclude` option in `tsconfig.app.json`.\n::\n\nCreate the `histoire.d.ts` file:\n\n```bash [histoire.d.ts]\ntouch histoire.d.ts\n```\n\nReference Histoire's types in this file:\n\n```ts [Example]\n\u002F\u002F\u002F \u003Creference types=\"@histoire\u002Fplugin-vue\u002Fcomponents\" \u002F>\n```\n\nRegister the new TSConfig in the `tsconfig.json`:\n\n```json [tsconfig.json]\n{\n  \"files\": [],\n  \"references\": [\n    {\n      \"path\": \".\u002Ftsconfig.app.json\"\n    },\n    {\n      \"path\": \".\u002Ftsconfig.node.json\"\n    },\n    {\n      \"path\": \".\u002Ftsconfig.story.json\" \u002F\u002F [!code ++]\n    }\n  ]\n}\n```\n\nUpdate `tsconfig.app.json` with an `exclude` option to avoid overlapping TSConfig capture:\n\n```json [tsconfig.app.json]\n{\n  \"extends\": \"@vue\u002Ftsconfig\u002Ftsconfig.dom.json\",\n  \"include\": [\n    \"src\u002F**\u002F*.ts\",\n    \"src\u002F**\u002F*.vue\"\n  ],\n  \"exclude\": [\n    \"src\u002F**\u002F*.story.vue\"\n  ]\n}\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nOverlapping TSConfig captures can lead to unexpected behavior and numerous issues. Ensure clear boundaries between TSConfigs to avoid conflicts.\n::\n\nIn the next article, we will enhance integration with the Vue.js ecosystem by creating a resolver for Unplugin Vue Component and a Nuxt module.\n",{"title":5,"description":1991},"the-complete-guide-to-building-a-vue-js-component-library",{"loc":1995,"images":2000},[2001,2002,2003,2004],{"loc":516},{"loc":692},{"loc":1305},{"loc":1601},"series\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fcreating-a-playground-and-a-storybook-for-components","HjTkxDPa6XJ7tGQOUZqOG6MXZxPMbzKbUnUPZ19bm-w",{"overview":2008,"chapters":2205},{"id":2009,"title":2010,"body":2011,"contentId":2190,"date":1990,"description":2191,"extension":1992,"github":2192,"meetTheInstructor":2194,"meta":2195,"navigation":372,"part":1993,"path":2196,"rawbody":2197,"robots":1993,"schemaOrg":1993,"seo":2198,"seriesSlug":1998,"sitemap":2199,"stem":2200,"subtitle":2201,"topics":2202,"__hash__":2204},"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":2012,"toc":2186},[2013,2016,2019,2031,2035,2038,2051,2055,2058,2173,2176,2180],[10,2014,2015],{},"Welcome! 👋",[10,2017,2018],{},"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,2020,2021,2022,2026,2027],{},"This series is somewhat of a sequel to the article ",[709,2023,2025],{"href":2024},"\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. ",[2028,2029,2030],"em",{},"You will learn how the most popular component libraries are constructed behind the scenes and how to create your own.",[2032,2033],"callout-read-more",{"id":2034},"f9754148-40bd-4df2-a144-f686e894b200",[10,2036,2037],{},"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,2039,2040,2041,2046,2047,119],{},"That's understandable. While ",[709,2042,2045],{"href":2043,"rel":2044},"https:\u002F\u002Fgithub.com\u002Funjs\u002Funbuild",[713],"unbuild"," is a powerful tool, it cannot match the flexibility, plugin ecosystem, and adoption of ",[709,2048,78],{"href":2049,"rel":2050},"https:\u002F\u002Fvite.dev\u002F",[713],[39,2052,2054],{"id":2053},"what-to-expect","What to expect",[10,2056,2057],{},"Throughout this series, we will address the following topics:",[19,2059,2060,2072,2105,2123,2140,2146,2155],{},[22,2061,2062,2065,2066,2071],{},[14,2063,2064],{},"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 ",[709,2067,2070],{"href":2068,"rel":2069},"https:\u002F\u002Feslint.org\u002F",[713],"ESLint"," to ensure code consistency.",[22,2073,2074,2077,2078,2083,2084,2088,2089,2094,2095,247,2100,119],{},[14,2075,2076],{},"Building a First Component with Vue.js and Tailwind CSS",": We'll create our first component with ",[709,2079,2082],{"href":2080,"rel":2081},"https:\u002F\u002Fvuejs.org\u002F",[713],"Vue.js",", ",[709,2085,36],{"href":2086,"rel":2087},"https:\u002F\u002Ftailwindcss.com\u002F",[713],", and ",[709,2090,2093],{"href":2091,"rel":2092},"https:\u002F\u002Fwww.tailwind-variants.org\u002F",[713],"Tailwind Variants"," using the most advanced and powerful techniques employed in popular component libraries like ",[709,2096,2099],{"href":2097,"rel":2098},"https:\u002F\u002Fwww.radix-vue.com\u002F",[713],"Radix Vue",[709,2101,2104],{"href":2102,"rel":2103},"https:\u002F\u002Fui.nuxt.com\u002F",[713],"Nuxt UI",[22,2106,2107,2110,2111,2116,2117,2122],{},[14,2108,2109],{},"A Better Development Experience with TypeScript and TSConfig",": We'll enhance our development experience by adding ",[709,2112,2115],{"href":2113,"rel":2114},"https:\u002F\u002Fwww.typescriptlang.org\u002F",[713],"TypeScript"," to our component library and configuring ",[709,2118,2121],{"href":2119,"rel":2120},"https:\u002F\u002Fwww.typescriptlang.org\u002Ftsconfig",[713],"TSConfig"," to ensure that our components are typed correctly and that we can take full advantage of TypeScript's features.",[22,2124,2125,2128,2129,247,2134,2139],{},[14,2126,2127],{},"Automatic Component Testing with Vitest and Testing Library",": We'll write tests for our components using ",[709,2130,2133],{"href":2131,"rel":2132},"https:\u002F\u002Fvitest.dev\u002Fguide\u002F",[713],"Vitest",[709,2135,2138],{"href":2136,"rel":2137},"https:\u002F\u002Ftesting-library.com\u002F",[713],"Testing Library"," to ensure that our components function as expected. This is crucial for a professional component library that remains reliable over time.",[22,2141,2142,2145],{},[14,2143,2144],{},"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,2147,2148,2150,2151,2154],{},[14,2149,5],{},": We'll create a playground to test our components in a real environment and a storybook with ",[709,2152,504],{"href":711,"rel":2153},[713]," 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,2156,2157,2160,2161,2166,2167,2172],{},[14,2158,2159],{},"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 ",[709,2162,2165],{"href":2163,"rel":2164},"https:\u002F\u002Fgithub.com\u002Funplugin\u002Funplugin-vue-components",[713],"Unplugin Vue Components"," and a ",[709,2168,2171],{"href":2169,"rel":2170},"https:\u002F\u002Fnuxt.com\u002Fdocs\u002Fguide\u002Fgoing-further\u002Fmodules",[713],"Nuxt module"," to utilize our components in a Nuxt application.",[10,2174,2175],{},"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? 😎",[39,2177,2179],{"id":2178},"chapters","Chapters",[2181,2182],"series-chapters-list",{"className":2183},[2184,2185],"mx-auto","max-w-5xl",{"title":57,"searchDepth":149,"depth":149,"links":2187},[2188,2189],{"id":2053,"depth":149,"text":2054},{"id":2178,"depth":149,"text":2179},"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":292,"repository":2193},"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":2010,"description":2191},{"loc":2196},"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.",[118,896,2203],"component library","2VSSnBlkuSLlt05n9MySLBFt6vBkgd7691eX-TK2cTs",[2206,2210,2214,2218,2222,2226,2227],{"contentId":2207,"title":2064,"description":2208,"path":2209,"part":64,"github":1993,"topics":1993},"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":2211,"title":2076,"description":2212,"path":2213,"part":149,"github":1993,"topics":1993},"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":2215,"title":2109,"description":2216,"path":2217,"part":161,"github":1993,"topics":1993},"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":2219,"title":2127,"description":2220,"path":2221,"part":369,"github":1993,"topics":1993},"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":2223,"title":2144,"description":2224,"path":2225,"part":376,"github":1993,"topics":1993},"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":1989,"title":5,"description":1991,"path":1995,"part":386,"github":1993,"topics":1993},{"contentId":2228,"title":2159,"description":2229,"path":2230,"part":405,"github":1993,"topics":1993},"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",1795016694932]