[{"data":1,"prerenderedAt":1478},["ShallowReactive",2],{"series-\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fa-better-development-experience-with-typescript-and-tsconfig":3,"series-context-\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library":1249},{"id":4,"title":5,"body":6,"contentId":1236,"date":1237,"description":1238,"extension":1239,"github":1240,"meetTheInstructor":1240,"meta":1241,"navigation":212,"part":196,"path":1242,"rawbody":1243,"robots":1240,"schemaOrg":1240,"seo":1244,"seriesSlug":1245,"sitemap":1246,"stem":1247,"subtitle":1240,"topics":1240,"__hash__":1248},"series\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fa-better-development-experience-with-typescript-and-tsconfig.md","A Better Development Experience with TypeScript and TSConfig",{"type":7,"value":8,"toc":1228},"minimark",[9,35,45,69,74,80,113,127,130,146,155,285,288,295,298,311,327,330,351,355,362,375,378,617,635,638,642,651,656,668,671,720,723,739,745,757,771,774,778,784,788,800,802,872,879,882,890,894,897,903,910,1031,1040,1043,1058,1070,1107,1111,1114,1121,1200,1212,1224],[10,11,12,13,17,18,22,23,26,27,30,31,34],"p",{},"Since the beginning of this series, we've been working with ",[14,15,16],"strong",{},"TypeScript"," by creating ",[19,20,21],"code",{},".ts"," files and using ",[19,24,25],{},"lang=\"ts\""," in the ",[19,28,29],{},"script"," section of ",[14,32,33],{},"Vue.js"," components.",[10,36,37,38,40,41,44],{},"However, we haven't configured ",[14,39,16],{}," in our project yet, so we're not leveraging its full potential. Additionally, one of the benefits of using TypeScript in a library is to expose types to the developers who will utilize it. This enables type checking and auto-completion in their ",[14,42,43],{},"IDE",".",[46,47,50],"callout",{"color":48,"icon":49},"success","i-ph-lightbulb-duotone",[10,51,52,53,56,57,60,61,64,65,68],{},"Check the ",[19,54,55],{},"dist"," folder in ",[19,58,59],{},"packages\u002Fhuchet-vue",". You'll notice only ",[19,62,63],{},".js"," files are present. We need to generate ",[19,66,67],{},".d.ts"," files to expose the types.",[70,71,73],"h2",{"id":72},"configuring-typescript","Configuring TypeScript",[10,75,76,77,79],{},"Let's start by installing TypeScript and the necessary Node.js types in ",[19,78,59],{},":",[81,82,88],"pre",{"className":83,"code":84,"filename":85,"language":86,"meta":87,"style":87},"language-bash shiki shiki-themes github-light github-light github-dark","pnpm add -D typescript @types\u002Fnode\n","terminal","bash","",[19,89,90],{"__ignoreMap":87},[91,92,95,99,103,107,110],"span",{"class":93,"line":94},"line",1,[91,96,98],{"class":97},"snPdu","pnpm",[91,100,102],{"class":101},"sIIMD"," add",[91,104,106],{"class":105},"sBjJW"," -D",[91,108,109],{"class":101}," typescript",[91,111,112],{"class":101}," @types\u002Fnode\n",[10,114,115,116,119,120,123,124,126],{},"Thanks to the extensive ",[14,117,118],{},"Vite plugin ecosystem",", we can use the ",[19,121,122],{},"vite-plugin-dts"," plugin to generate ",[19,125,67],{}," files for our library.",[10,128,129],{},"Install it:",[81,131,133],{"className":83,"code":132,"filename":67,"language":86,"meta":87,"style":87},"pnpm add -D vite-plugin-dts\n",[19,134,135],{"__ignoreMap":87},[91,136,137,139,141,143],{"class":93,"line":94},[91,138,98],{"class":97},[91,140,102],{"class":101},[91,142,106],{"class":105},[91,144,145],{"class":101}," vite-plugin-dts\n",[10,147,148,149,152,153,79],{},"Next, update the ",[19,150,151],{},"vite.config.ts"," file in ",[19,154,59],{},[81,156,160],{"className":157,"code":158,"filename":151,"language":159,"meta":87,"style":87},"language-ts shiki shiki-themes github-light github-light github-dark has-diff","import Vue from '@vitejs\u002Fplugin-vue'\nimport { defineConfig } from 'vite'\nimport Dts from 'vite-plugin-dts' \u002F\u002F [!code ++]\n\nexport default defineConfig({\n  plugins: [\n    Vue(),\n    Dts(), \u002F\u002F [!code ++]\n  ],\n  build: {\n    \u002F\u002F ...\n  }\n})\n","ts",[19,161,162,178,191,207,214,229,235,244,254,260,266,273,279],{"__ignoreMap":87},[91,163,164,168,172,175],{"class":93,"line":94},[91,165,167],{"class":166},"s8jYJ","import",[91,169,171],{"class":170},"sxrX7"," Vue ",[91,173,174],{"class":166},"from",[91,176,177],{"class":101}," '@vitejs\u002Fplugin-vue'\n",[91,179,181,183,186,188],{"class":93,"line":180},2,[91,182,167],{"class":166},[91,184,185],{"class":170}," { defineConfig } ",[91,187,174],{"class":166},[91,189,190],{"class":101}," 'vite'\n",[91,192,197,199,202,204],{"class":193,"line":196},[93,194,195],"diff","add",3,[91,198,167],{"class":166},[91,200,201],{"class":170}," Dts ",[91,203,174],{"class":166},[91,205,206],{"class":101}," 'vite-plugin-dts'",[91,208,210],{"class":93,"line":209},4,[91,211,213],{"emptyLinePlaceholder":212},true,"\n",[91,215,217,220,223,226],{"class":93,"line":216},5,[91,218,219],{"class":166},"export",[91,221,222],{"class":166}," default",[91,224,225],{"class":97}," defineConfig",[91,227,228],{"class":170},"({\n",[91,230,232],{"class":93,"line":231},6,[91,233,234],{"class":170},"  plugins: [\n",[91,236,238,241],{"class":93,"line":237},7,[91,239,240],{"class":97},"    Vue",[91,242,243],{"class":170},"(),\n",[91,245,248,251],{"class":246,"line":247},[93,194,195],8,[91,249,250],{"class":97},"    Dts",[91,252,253],{"class":170},"(), ",[91,255,257],{"class":93,"line":256},9,[91,258,259],{"class":170},"  ],\n",[91,261,263],{"class":93,"line":262},10,[91,264,265],{"class":170},"  build: {\n",[91,267,269],{"class":93,"line":268},11,[91,270,272],{"class":271},"sCsY4","    \u002F\u002F ...\n",[91,274,276],{"class":93,"line":275},12,[91,277,278],{"class":170},"  }\n",[91,280,282],{"class":93,"line":281},13,[91,283,284],{"class":170},"})\n",[10,286,287],{},"Does it work now? Not yet. If it were that simple, I wouldn't write an entire article about it!",[10,289,290,291,294],{},"When using TypeScript, we have to configure it through a ",[19,292,293],{},"tsconfig.json"," file. This file includes numerous options to inform TypeScript about the project type, including global types and variables, file paths, and even the desired code compilation method.",[10,296,297],{},"Writing this the first time can be tedious, but fortunately, some projects provide a base configuration to extend from.",[10,299,300,301,303,304,306,307,310],{},"Another issue with ",[19,302,293],{}," is that a package can have more than one. Our ",[19,305,151],{}," file and ",[19,308,309],{},".vue"," files have different contexts. The first needs access to the Node.js API, while the second needs access to the DOM and browser API.",[10,312,313,314,316,317,326],{},"We can resolve this by using a single ",[19,315,293],{}," file with the ",[318,319,323],"a",{"href":320,"rel":321},"https:\u002F\u002Fwww.typescriptlang.org\u002Ftsconfig\u002F#references",[322],"nofollow",[19,324,325],{},"references"," option. This allows us to split a TSConfig file into multiple files, each targeting a specific context.",[10,328,329],{},"Here's the plan:",[331,332,333,339,345],"ol",{},[334,335,336,338],"li",{},[19,337,293],{}," to combine the two contexts.",[334,340,341,344],{},[19,342,343],{},"tsconfig.node.json"," for the Node.js context.",[334,346,347,350],{},[19,348,349],{},"tsconfig.app.json"," for the Vue.js context.",[70,352,354],{"id":353},"the-node-typescript-context","The Node TypeScript context",[10,356,357,358,152,360,79],{},"Create the ",[19,359,343],{},[19,361,59],{},[81,363,365],{"className":83,"code":364,"filename":343,"language":86,"meta":87,"style":87},"touch tsconfig.node.json\n",[19,366,367],{"__ignoreMap":87},[91,368,369,372],{"class":93,"line":94},[91,370,371],{"class":97},"touch",[91,373,374],{"class":101}," tsconfig.node.json\n",[10,376,377],{},"Populate it with the following:",[81,379,384],{"className":380,"code":381,"filename":382,"language":383,"meta":87,"style":87},"language-json shiki shiki-themes github-light github-light github-dark","{\n  \"compilerOptions\": {\n    \"tsBuildInfoFile\": \".\u002Fnode_modules\u002F.tmp\u002Ftsconfig.node.tsbuildinfo\",\n    \"target\": \"ES2022\",\n    \"lib\": [\"ES2023\"],\n    \"moduleDetection\": \"force\",\n    \"types\": [\"node\"],\n    \"module\": \"ESNext\",\n    \"moduleResolution\": \"Bundler\",\n    \"allowImportingTsExtensions\": true,\n    \"strict\": true,\n    \"noFallthroughCasesInSwitch\": true,\n    \"noUnusedLocals\": true,\n    \"noUnusedParameters\": true,\n    \"noEmit\": true,\n    \"isolatedModules\": true,\n    \"skipLibCheck\": true,\n    \"noUncheckedSideEffectImports\": true\n  },\n  \"include\": [\"vite.config.ts\"]\n}\n","Example","json",[19,385,386,391,399,413,425,439,451,463,475,487,499,510,521,532,544,556,568,580,591,597,611],{"__ignoreMap":87},[91,387,388],{"class":93,"line":94},[91,389,390],{"class":170},"{\n",[91,392,393,396],{"class":93,"line":180},[91,394,395],{"class":105},"  \"compilerOptions\"",[91,397,398],{"class":170},": {\n",[91,400,401,404,407,410],{"class":93,"line":196},[91,402,403],{"class":105},"    \"tsBuildInfoFile\"",[91,405,406],{"class":170},": ",[91,408,409],{"class":101},"\".\u002Fnode_modules\u002F.tmp\u002Ftsconfig.node.tsbuildinfo\"",[91,411,412],{"class":170},",\n",[91,414,415,418,420,423],{"class":93,"line":209},[91,416,417],{"class":105},"    \"target\"",[91,419,406],{"class":170},[91,421,422],{"class":101},"\"ES2022\"",[91,424,412],{"class":170},[91,426,427,430,433,436],{"class":93,"line":216},[91,428,429],{"class":105},"    \"lib\"",[91,431,432],{"class":170},": [",[91,434,435],{"class":101},"\"ES2023\"",[91,437,438],{"class":170},"],\n",[91,440,441,444,446,449],{"class":93,"line":231},[91,442,443],{"class":105},"    \"moduleDetection\"",[91,445,406],{"class":170},[91,447,448],{"class":101},"\"force\"",[91,450,412],{"class":170},[91,452,453,456,458,461],{"class":93,"line":237},[91,454,455],{"class":105},"    \"types\"",[91,457,432],{"class":170},[91,459,460],{"class":101},"\"node\"",[91,462,438],{"class":170},[91,464,465,468,470,473],{"class":93,"line":247},[91,466,467],{"class":105},"    \"module\"",[91,469,406],{"class":170},[91,471,472],{"class":101},"\"ESNext\"",[91,474,412],{"class":170},[91,476,477,480,482,485],{"class":93,"line":256},[91,478,479],{"class":105},"    \"moduleResolution\"",[91,481,406],{"class":170},[91,483,484],{"class":101},"\"Bundler\"",[91,486,412],{"class":170},[91,488,489,492,494,497],{"class":93,"line":262},[91,490,491],{"class":105},"    \"allowImportingTsExtensions\"",[91,493,406],{"class":170},[91,495,496],{"class":105},"true",[91,498,412],{"class":170},[91,500,501,504,506,508],{"class":93,"line":268},[91,502,503],{"class":105},"    \"strict\"",[91,505,406],{"class":170},[91,507,496],{"class":105},[91,509,412],{"class":170},[91,511,512,515,517,519],{"class":93,"line":275},[91,513,514],{"class":105},"    \"noFallthroughCasesInSwitch\"",[91,516,406],{"class":170},[91,518,496],{"class":105},[91,520,412],{"class":170},[91,522,523,526,528,530],{"class":93,"line":281},[91,524,525],{"class":105},"    \"noUnusedLocals\"",[91,527,406],{"class":170},[91,529,496],{"class":105},[91,531,412],{"class":170},[91,533,535,538,540,542],{"class":93,"line":534},14,[91,536,537],{"class":105},"    \"noUnusedParameters\"",[91,539,406],{"class":170},[91,541,496],{"class":105},[91,543,412],{"class":170},[91,545,547,550,552,554],{"class":93,"line":546},15,[91,548,549],{"class":105},"    \"noEmit\"",[91,551,406],{"class":170},[91,553,496],{"class":105},[91,555,412],{"class":170},[91,557,559,562,564,566],{"class":93,"line":558},16,[91,560,561],{"class":105},"    \"isolatedModules\"",[91,563,406],{"class":170},[91,565,496],{"class":105},[91,567,412],{"class":170},[91,569,571,574,576,578],{"class":93,"line":570},17,[91,572,573],{"class":105},"    \"skipLibCheck\"",[91,575,406],{"class":170},[91,577,496],{"class":105},[91,579,412],{"class":170},[91,581,583,586,588],{"class":93,"line":582},18,[91,584,585],{"class":105},"    \"noUncheckedSideEffectImports\"",[91,587,406],{"class":170},[91,589,590],{"class":105},"true\n",[91,592,594],{"class":93,"line":593},19,[91,595,596],{"class":170},"  },\n",[91,598,600,603,605,608],{"class":93,"line":599},20,[91,601,602],{"class":105},"  \"include\"",[91,604,432],{"class":170},[91,606,607],{"class":101},"\"vite.config.ts\"",[91,609,610],{"class":170},"]\n",[91,612,614],{"class":93,"line":613},21,[91,615,616],{"class":170},"}\n",[10,618,619,620,623,624,627,628,631,632,634],{},"This file is similar to what's provided in any ",[14,621,622],{},"Vite"," template, except we've added the ",[19,625,626],{},"types"," option set to ",[19,629,630],{},"[\"node\"]"," to ensure Node.js types are available in the Vite configuration file. This configuration targets only the ",[19,633,151],{}," file.",[10,636,637],{},"This forms our first TypeScript context.",[70,639,641],{"id":640},"the-vuejs-typescript-context","The Vue.js TypeScript context",[10,643,644,645,648,649,44],{},"The second context will target the Vue.js files and TypeScript files from our ",[19,646,647],{},"src"," folder, named ",[19,650,349],{},[10,652,357,653,655],{},[19,654,349],{}," file:",[81,657,659],{"className":83,"code":658,"filename":349,"language":86,"meta":87,"style":87},"touch tsconfig.app.json\n",[19,660,661],{"__ignoreMap":87},[91,662,663,665],{"class":93,"line":94},[91,664,371],{"class":97},[91,666,667],{"class":101}," tsconfig.app.json\n",[10,669,670],{},"Include the following content:",[81,672,674],{"className":380,"code":673,"filename":382,"language":383,"meta":87,"style":87},"{\n  \"extends\": \"@vue\u002Ftsconfig\u002Ftsconfig.dom.json\",\n  \"include\": [\n    \"src\u002F**\u002F*.ts\",\n    \"src\u002F**\u002F*.vue\"\n  ]\n}\n",[19,675,676,680,692,699,706,711,716],{"__ignoreMap":87},[91,677,678],{"class":93,"line":94},[91,679,390],{"class":170},[91,681,682,685,687,690],{"class":93,"line":180},[91,683,684],{"class":105},"  \"extends\"",[91,686,406],{"class":170},[91,688,689],{"class":101},"\"@vue\u002Ftsconfig\u002Ftsconfig.dom.json\"",[91,691,412],{"class":170},[91,693,694,696],{"class":93,"line":196},[91,695,602],{"class":105},[91,697,698],{"class":170},": [\n",[91,700,701,704],{"class":93,"line":209},[91,702,703],{"class":101},"    \"src\u002F**\u002F*.ts\"",[91,705,412],{"class":170},[91,707,708],{"class":93,"line":216},[91,709,710],{"class":101},"    \"src\u002F**\u002F*.vue\"\n",[91,712,713],{"class":93,"line":231},[91,714,715],{"class":170},"  ]\n",[91,717,718],{"class":93,"line":237},[91,719,616],{"class":170},[10,721,722],{},"Before using this setup, install the Vue.js TypeScript base configuration:",[81,724,726],{"className":83,"code":725,"filename":85,"language":86,"meta":87,"style":87},"pnpm add -D @vue\u002Ftsconfig\n",[19,727,728],{"__ignoreMap":87},[91,729,730,732,734,736],{"class":93,"line":94},[91,731,98],{"class":97},[91,733,102],{"class":101},[91,735,106],{"class":105},[91,737,738],{"class":101}," @vue\u002Ftsconfig\n",[10,740,741,742,744],{},"Vue.js offers a base configuration to expand on, crucial because TypeScript evolves rapidly, and ",[14,743,33],{}," requires specific configurations. Writing a TypeScript configuration from scratch isn't appealing to most developers.",[46,746,747],{"color":48,"icon":49},[10,748,749,750,752,753,756],{},"I recommend examining the ",[19,751,293],{}," file in the ",[19,754,755],{},"@vue\u002Ftsconfig"," package. It's well documented and offers valuable insights.",[10,758,759,760,763,764,766,767,770],{},"Our configuration extends the Vue.js setup with the ",[19,761,762],{},"extends"," option and targets the ",[19,765,647],{}," folder using the ",[19,768,769],{},"include"," option. It's straightforward and functional.",[10,772,773],{},"This is our second TypeScript context.",[70,775,777],{"id":776},"the-global-typescript-configuration","The global TypeScript configuration",[10,779,780,781,783],{},"Now, create the ",[19,782,293],{}," file to unify the two contexts. This file doesn't define a new context or compiler options but references the two other contexts for the TypeScript compiler to use as needed.",[10,785,357,786,655],{},[19,787,293],{},[81,789,791],{"className":83,"code":790,"filename":293,"language":86,"meta":87,"style":87},"touch tsconfig.json\n",[19,792,793],{"__ignoreMap":87},[91,794,795,797],{"class":93,"line":94},[91,796,371],{"class":97},[91,798,799],{"class":101}," tsconfig.json\n",[10,801,670],{},[81,803,805],{"className":380,"code":804,"filename":382,"language":383,"meta":87,"style":87},"{\n  \"files\": [],\n  \"references\": [\n    {\n      \"path\": \".\u002Ftsconfig.app.json\"\n    },\n    {\n      \"path\": \".\u002Ftsconfig.node.json\"\n    }\n  ]\n}\n",[19,806,807,811,819,826,831,841,846,850,859,864,868],{"__ignoreMap":87},[91,808,809],{"class":93,"line":94},[91,810,390],{"class":170},[91,812,813,816],{"class":93,"line":180},[91,814,815],{"class":105},"  \"files\"",[91,817,818],{"class":170},": [],\n",[91,820,821,824],{"class":93,"line":196},[91,822,823],{"class":105},"  \"references\"",[91,825,698],{"class":170},[91,827,828],{"class":93,"line":209},[91,829,830],{"class":170},"    {\n",[91,832,833,836,838],{"class":93,"line":216},[91,834,835],{"class":105},"      \"path\"",[91,837,406],{"class":170},[91,839,840],{"class":101},"\".\u002Ftsconfig.app.json\"\n",[91,842,843],{"class":93,"line":231},[91,844,845],{"class":170},"    },\n",[91,847,848],{"class":93,"line":237},[91,849,830],{"class":170},[91,851,852,854,856],{"class":93,"line":247},[91,853,835],{"class":105},[91,855,406],{"class":170},[91,857,858],{"class":101},"\".\u002Ftsconfig.node.json\"\n",[91,860,861],{"class":93,"line":256},[91,862,863],{"class":170},"    }\n",[91,865,866],{"class":93,"line":262},[91,867,715],{"class":170},[91,869,870],{"class":93,"line":268},[91,871,616],{"class":170},[10,873,874,875,878],{},"The empty ",[19,876,877],{},"files"," array is crucial to avoid including every project file. Each reference has its own context, so we must ensure that only one context targets a file.",[10,880,881],{},"This forms our global TypeScript configuration.",[46,883,884],{"color":48,"icon":49},[10,885,886,887,889],{},"To verify everything works correctly, attempt to import a Node.js module in ",[19,888,151],{}," where it should be accessible and in a Vue.js file where it should not be.",[70,891,893],{"id":892},"generating-the-types","Generating the types",[10,895,896],{},"With our TypeScript configurations set up, we can proceed to generate the types for our library.",[10,898,899,900,902],{},"Since we are combining two contexts, the ",[19,901,122],{}," plugin needs explicit context direction.",[10,904,905,906,152,908,79],{},"Update the ",[19,907,151],{},[19,909,59],{},[81,911,914],{"className":912,"code":913,"filename":151,"language":159,"meta":87,"style":87},"language-ts shiki shiki-themes github-light github-light github-dark","import { resolve } from 'node:path'\nimport Vue from '@vitejs\u002Fplugin-vue'\nimport { defineConfig } from 'vite'\nimport Dts from 'vite-plugin-dts'\n\nexport default defineConfig({\n  plugins: [\n    Vue(),\n    Dts({\n      tsconfigPath: resolve(__dirname, 'tsconfig.app.json'),\n    })\n  ],\n  build: {\n    \u002F\u002F ...\n  },\n})\n",[19,915,916,928,938,948,959,963,973,977,983,989,1006,1011,1015,1019,1023,1027],{"__ignoreMap":87},[91,917,918,920,923,925],{"class":93,"line":94},[91,919,167],{"class":166},[91,921,922],{"class":170}," { resolve } ",[91,924,174],{"class":166},[91,926,927],{"class":101}," 'node:path'\n",[91,929,930,932,934,936],{"class":93,"line":180},[91,931,167],{"class":166},[91,933,171],{"class":170},[91,935,174],{"class":166},[91,937,177],{"class":101},[91,939,940,942,944,946],{"class":93,"line":196},[91,941,167],{"class":166},[91,943,185],{"class":170},[91,945,174],{"class":166},[91,947,190],{"class":101},[91,949,950,952,954,956],{"class":93,"line":209},[91,951,167],{"class":166},[91,953,201],{"class":170},[91,955,174],{"class":166},[91,957,958],{"class":101}," 'vite-plugin-dts'\n",[91,960,961],{"class":93,"line":216},[91,962,213],{"emptyLinePlaceholder":212},[91,964,965,967,969,971],{"class":93,"line":231},[91,966,219],{"class":166},[91,968,222],{"class":166},[91,970,225],{"class":97},[91,972,228],{"class":170},[91,974,975],{"class":93,"line":237},[91,976,234],{"class":170},[91,978,979,981],{"class":93,"line":247},[91,980,240],{"class":97},[91,982,243],{"class":170},[91,984,985,987],{"class":93,"line":256},[91,986,250],{"class":97},[91,988,228],{"class":170},[91,990,991,994,997,1000,1003],{"class":93,"line":262},[91,992,993],{"class":170},"      tsconfigPath: ",[91,995,996],{"class":97},"resolve",[91,998,999],{"class":170},"(__dirname, ",[91,1001,1002],{"class":101},"'tsconfig.app.json'",[91,1004,1005],{"class":170},"),\n",[91,1007,1008],{"class":93,"line":268},[91,1009,1010],{"class":170},"    })\n",[91,1012,1013],{"class":93,"line":275},[91,1014,259],{"class":170},[91,1016,1017],{"class":93,"line":281},[91,1018,265],{"class":170},[91,1020,1021],{"class":93,"line":534},[91,1022,272],{"class":271},[91,1024,1025],{"class":93,"line":546},[91,1026,596],{"class":170},[91,1028,1029],{"class":93,"line":558},[91,1030,284],{"class":170},[10,1032,1033,1034,1036,1037,1039],{},"We use the ",[19,1035,349],{}," file since Vite builds Vue.js and TypeScript files from the ",[19,1038,647],{}," folder.",[10,1041,1042],{},"Proceed to generate the types:",[81,1044,1046],{"className":83,"code":1045,"filename":349,"language":86,"meta":87,"style":87},"pnpm run build\n",[19,1047,1048],{"__ignoreMap":87},[91,1049,1050,1052,1055],{"class":93,"line":94},[91,1051,98],{"class":97},[91,1053,1054],{"class":101}," run",[91,1056,1057],{"class":101}," build\n",[10,1059,1060,1061,1063,1064,1066,1067,1069],{},"In our ",[19,1062,55],{}," folder, a ",[19,1065,626],{}," folder containing the ",[19,1068,67],{}," files should appear.",[81,1071,1075],{"className":1072,"code":1073,"filename":67,"language":1074,"meta":87,"style":87},"language-txt shiki shiki-themes github-light github-light github-dark","dist\n├── index.d.ts\n├── index.mjs\n└── Button\n    ├── Button.vue.d.ts\n    └── index.d.ts\n","txt",[19,1076,1077,1082,1087,1092,1097,1102],{"__ignoreMap":87},[91,1078,1079],{"class":93,"line":94},[91,1080,1081],{},"dist\n",[91,1083,1084],{"class":93,"line":180},[91,1085,1086],{},"├── index.d.ts\n",[91,1088,1089],{"class":93,"line":196},[91,1090,1091],{},"├── index.mjs\n",[91,1093,1094],{"class":93,"line":209},[91,1095,1096],{},"└── Button\n",[91,1098,1099],{"class":93,"line":216},[91,1100,1101],{},"    ├── Button.vue.d.ts\n",[91,1103,1104],{"class":93,"line":231},[91,1105,1106],{},"    └── index.d.ts\n",[70,1108,1110],{"id":1109},"exposing-the-types","Exposing the types",[10,1112,1113],{},"Having generated the types, the next step is to expose them to developers using our library.",[10,1115,905,1116,152,1119,79],{},[19,1117,1118],{},"package.json",[19,1120,59],{},[81,1122,1124],{"className":380,"code":1123,"filename":1118,"language":383,"meta":87,"style":87},"{\n  \"exports\": {\n    \".\": {\n      \"types\": \".\u002Fdist\u002Findex.d.ts\",\n      \"import\": \".\u002Fdist\u002Findex.mjs\"\n    }\n  },\n  \"main\": \".\u002Fdist\u002Findex.mjs\",\n  \"types\": \"dist\u002Findex.d.ts\"\n}\n",[19,1125,1126,1130,1137,1144,1156,1166,1170,1174,1186,1196],{"__ignoreMap":87},[91,1127,1128],{"class":93,"line":94},[91,1129,390],{"class":170},[91,1131,1132,1135],{"class":93,"line":180},[91,1133,1134],{"class":105},"  \"exports\"",[91,1136,398],{"class":170},[91,1138,1139,1142],{"class":93,"line":196},[91,1140,1141],{"class":105},"    \".\"",[91,1143,398],{"class":170},[91,1145,1146,1149,1151,1154],{"class":93,"line":209},[91,1147,1148],{"class":105},"      \"types\"",[91,1150,406],{"class":170},[91,1152,1153],{"class":101},"\".\u002Fdist\u002Findex.d.ts\"",[91,1155,412],{"class":170},[91,1157,1158,1161,1163],{"class":93,"line":216},[91,1159,1160],{"class":105},"      \"import\"",[91,1162,406],{"class":170},[91,1164,1165],{"class":101},"\".\u002Fdist\u002Findex.mjs\"\n",[91,1167,1168],{"class":93,"line":231},[91,1169,863],{"class":170},[91,1171,1172],{"class":93,"line":237},[91,1173,596],{"class":170},[91,1175,1176,1179,1181,1184],{"class":93,"line":247},[91,1177,1178],{"class":105},"  \"main\"",[91,1180,406],{"class":170},[91,1182,1183],{"class":101},"\".\u002Fdist\u002Findex.mjs\"",[91,1185,412],{"class":170},[91,1187,1188,1191,1193],{"class":93,"line":256},[91,1189,1190],{"class":105},"  \"types\"",[91,1192,406],{"class":170},[91,1194,1195],{"class":101},"\"dist\u002Findex.d.ts\"\n",[91,1197,1198],{"class":93,"line":262},[91,1199,616],{"class":170},[10,1201,1202,1203,1205,1206,752,1209,1211],{},"We set the ",[19,1204,626],{}," field to point to the ",[19,1207,1208],{},"index.d.ts",[19,1210,55],{}," folder, ensuring types are available in the IDE when developers import our library.",[46,1213,1216],{"color":1214,"icon":1215},"primary","i-ph-info-duotone",[10,1217,1218,1219,1221,1222,634],{},"Ensure the ",[19,1220,626],{}," field precedes any other exports in the ",[19,1223,1118],{},[1225,1226,1227],"style",{},"html pre.shiki code .snPdu, html code.shiki .snPdu{--shiki-light:#6F42C1;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sIIMD, html code.shiki .sIIMD{--shiki-light:#032F62;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sBjJW, html code.shiki .sBjJW{--shiki-light:#005CC5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s8jYJ, html code.shiki .s8jYJ{--shiki-light:#D73A49;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sxrX7, html code.shiki .sxrX7{--shiki-light:#24292E;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}",{"title":87,"searchDepth":180,"depth":180,"links":1229},[1230,1231,1232,1233,1234,1235],{"id":72,"depth":180,"text":73},{"id":353,"depth":180,"text":354},{"id":640,"depth":180,"text":641},{"id":776,"depth":180,"text":777},{"id":892,"depth":180,"text":893},{"id":1109,"depth":180,"text":1110},"c2d651b0-4487-472d-b55a-b3cf195bcba8","2024-11-24","Learn how to configure TypeScript with multiple contexts and generate types for a library to expose types to developers.","md",null,{},"\u002Fseries\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fa-better-development-experience-with-typescript-and-tsconfig","---\ncontentId: c2d651b0-4487-472d-b55a-b3cf195bcba8\npart: 3\ntitle: A Better Development Experience with TypeScript and TSConfig\ndescription: \"Learn how to configure TypeScript with multiple contexts and generate types for a library to expose types to developers.\"\ndate: 2024-11-24\nseriesSlug: the-complete-guide-to-building-a-vue-js-component-library\n---\n\nSince the beginning of this series, we've been working with **TypeScript** by creating `.ts` files and using `lang=\"ts\"` in the `script` section of **Vue.js** components.\n\nHowever, we haven't configured **TypeScript** in our project yet, so we're not leveraging its full potential. Additionally, one of the benefits of using TypeScript in a library is to expose types to the developers who will utilize it. This enables type checking and auto-completion in their **IDE**.\n\n::callout{icon=\"i-ph-lightbulb-duotone\" color=\"success\"}\nCheck the `dist` folder in `packages\u002Fhuchet-vue`. You'll notice only `.js` files are present. We need to generate `.d.ts` files to expose the types.\n::\n\n## Configuring TypeScript\n\nLet's start by installing TypeScript and the necessary Node.js types in `packages\u002Fhuchet-vue`:\n\n```bash [terminal]\npnpm add -D typescript @types\u002Fnode\n```\n\nThanks to the extensive **Vite plugin ecosystem**, we can use the `vite-plugin-dts` plugin to generate `.d.ts` files for our library.\n\nInstall it:\n\n```bash [.d.ts]\npnpm add -D vite-plugin-dts\n```\n\nNext, update the `vite.config.ts` file in `packages\u002Fhuchet-vue`:\n\n```ts [vite.config.ts]\nimport Vue from '@vitejs\u002Fplugin-vue'\nimport { defineConfig } from 'vite'\nimport Dts from 'vite-plugin-dts' \u002F\u002F [!code ++]\n\nexport default defineConfig({\n  plugins: [\n    Vue(),\n    Dts(), \u002F\u002F [!code ++]\n  ],\n  build: {\n    \u002F\u002F ...\n  }\n})\n```\n\nDoes it work now? Not yet. If it were that simple, I wouldn't write an entire article about it!\n\nWhen using TypeScript, we have to configure it through a `tsconfig.json` file. This file includes numerous options to inform TypeScript about the project type, including global types and variables, file paths, and even the desired code compilation method.\n\nWriting this the first time can be tedious, but fortunately, some projects provide a base configuration to extend from.\n\nAnother issue with `tsconfig.json` is that a package can have more than one. Our `vite.config.ts` file and `.vue` files have different contexts. The first needs access to the Node.js API, while the second needs access to the DOM and browser API.\n\nWe can resolve this by using a single `tsconfig.json` file with the [`references`](https:\u002F\u002Fwww.typescriptlang.org\u002Ftsconfig\u002F#references) option. This allows us to split a TSConfig file into multiple files, each targeting a specific context.\n\nHere's the plan:\n\n1. `tsconfig.json` to combine the two contexts.\n2. `tsconfig.node.json` for the Node.js context.\n3. `tsconfig.app.json` for the Vue.js context.\n\n## The Node TypeScript context\n\nCreate the `tsconfig.node.json` file in `packages\u002Fhuchet-vue`:\n\n```bash [tsconfig.node.json]\ntouch tsconfig.node.json\n```\n\nPopulate it with the following:\n\n```json [Example]\n{\n  \"compilerOptions\": {\n    \"tsBuildInfoFile\": \".\u002Fnode_modules\u002F.tmp\u002Ftsconfig.node.tsbuildinfo\",\n    \"target\": \"ES2022\",\n    \"lib\": [\"ES2023\"],\n    \"moduleDetection\": \"force\",\n    \"types\": [\"node\"],\n    \"module\": \"ESNext\",\n    \"moduleResolution\": \"Bundler\",\n    \"allowImportingTsExtensions\": true,\n    \"strict\": true,\n    \"noFallthroughCasesInSwitch\": true,\n    \"noUnusedLocals\": true,\n    \"noUnusedParameters\": true,\n    \"noEmit\": true,\n    \"isolatedModules\": true,\n    \"skipLibCheck\": true,\n    \"noUncheckedSideEffectImports\": true\n  },\n  \"include\": [\"vite.config.ts\"]\n}\n```\n\nThis file is similar to what's provided in any **Vite** template, except we've added the `types` option set to `[\"node\"]` to ensure Node.js types are available in the Vite configuration file. This configuration targets only the `vite.config.ts` file.\n\nThis forms our first TypeScript context.\n\n## The Vue.js TypeScript context\n\nThe second context will target the Vue.js files and TypeScript files from our `src` folder, named `tsconfig.app.json`.\n\nCreate the `tsconfig.app.json` file:\n\n```bash [tsconfig.app.json]\ntouch tsconfig.app.json\n```\n\nInclude the following content:\n\n```json [Example]\n{\n  \"extends\": \"@vue\u002Ftsconfig\u002Ftsconfig.dom.json\",\n  \"include\": [\n    \"src\u002F**\u002F*.ts\",\n    \"src\u002F**\u002F*.vue\"\n  ]\n}\n```\n\nBefore using this setup, install the Vue.js TypeScript base configuration:\n\n```bash [terminal]\npnpm add -D @vue\u002Ftsconfig\n```\n\nVue.js offers a base configuration to expand on, crucial because TypeScript evolves rapidly, and **Vue.js** requires specific configurations. Writing a TypeScript configuration from scratch isn't appealing to most developers.\n\n::callout{icon=\"i-ph-lightbulb-duotone\" color=\"success\"}\nI recommend examining the `tsconfig.json` file in the `@vue\u002Ftsconfig` package. It's well documented and offers valuable insights.\n::\n\nOur configuration extends the Vue.js setup with the `extends` option and targets the `src` folder using the `include` option. It's straightforward and functional.\n\nThis is our second TypeScript context.\n\n## The global TypeScript configuration\n\nNow, create the `tsconfig.json` file to unify the two contexts. This file doesn't define a new context or compiler options but references the two other contexts for the TypeScript compiler to use as needed.\n\nCreate the `tsconfig.json` file:\n\n```bash [tsconfig.json]\ntouch tsconfig.json\n```\n\nInclude the following content:\n\n```json [Example]\n{\n  \"files\": [],\n  \"references\": [\n    {\n      \"path\": \".\u002Ftsconfig.app.json\"\n    },\n    {\n      \"path\": \".\u002Ftsconfig.node.json\"\n    }\n  ]\n}\n```\n\nThe empty `files` array is crucial to avoid including every project file. Each reference has its own context, so we must ensure that only one context targets a file.\n\nThis forms our global TypeScript configuration.\n\n::callout{icon=\"i-ph-lightbulb-duotone\" color=\"success\"}\nTo verify everything works correctly, attempt to import a Node.js module in `vite.config.ts` where it should be accessible and in a Vue.js file where it should not be.\n::\n\n## Generating the types\n\nWith our TypeScript configurations set up, we can proceed to generate the types for our library.\n\nSince we are combining two contexts, the `vite-plugin-dts` plugin needs explicit context direction.\n\nUpdate the `vite.config.ts` file in `packages\u002Fhuchet-vue`:\n\n```ts [vite.config.ts]\nimport { resolve } from 'node:path'\nimport Vue from '@vitejs\u002Fplugin-vue'\nimport { defineConfig } from 'vite'\nimport Dts from 'vite-plugin-dts'\n\nexport default defineConfig({\n  plugins: [\n    Vue(),\n    Dts({\n      tsconfigPath: resolve(__dirname, 'tsconfig.app.json'),\n    })\n  ],\n  build: {\n    \u002F\u002F ...\n  },\n})\n```\n\nWe use the `tsconfig.app.json` file since Vite builds Vue.js and TypeScript files from the `src` folder.\n\nProceed to generate the types:\n\n```bash [tsconfig.app.json]\npnpm run build\n```\n\nIn our `dist` folder, a `types` folder containing the `.d.ts` files should appear.\n\n```txt [.d.ts]\ndist\n├── index.d.ts\n├── index.mjs\n└── Button\n    ├── Button.vue.d.ts\n    └── index.d.ts\n```\n\n## Exposing the types\n\nHaving generated the types, the next step is to expose them to developers using our library.\n\nUpdate the `package.json` file in `packages\u002Fhuchet-vue`:\n\n```json [package.json]\n{\n  \"exports\": {\n    \".\": {\n      \"types\": \".\u002Fdist\u002Findex.d.ts\",\n      \"import\": \".\u002Fdist\u002Findex.mjs\"\n    }\n  },\n  \"main\": \".\u002Fdist\u002Findex.mjs\",\n  \"types\": \"dist\u002Findex.d.ts\"\n}\n```\n\nWe set the `types` field to point to the `index.d.ts` file in the `dist` folder, ensuring types are available in the IDE when developers import our library.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"primary\"}\nEnsure the `types` field precedes any other exports in the `package.json` file.\n::\n",{"title":5,"description":1238},"the-complete-guide-to-building-a-vue-js-component-library",{"loc":1242},"series\u002Fthe-complete-guide-to-building-a-vue-js-component-library\u002Fa-better-development-experience-with-typescript-and-tsconfig","pGn5EH0qoosD_mDc7wCbwjAsqm-o7l4h1dDu6ADnlfY",{"overview":1250,"chapters":1452},{"id":1251,"title":1252,"body":1253,"contentId":1434,"date":1237,"description":1435,"extension":1239,"github":1436,"meetTheInstructor":1439,"meta":1440,"navigation":212,"part":1240,"path":1441,"rawbody":1442,"robots":1240,"schemaOrg":1240,"seo":1443,"seriesSlug":1245,"sitemap":1444,"stem":1445,"subtitle":1446,"topics":1447,"__hash__":1451},"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":1254,"toc":1430},[1255,1258,1261,1273,1277,1280,1293,1297,1300,1417,1420,1424],[10,1256,1257],{},"Welcome! 👋",[10,1259,1260],{},"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,1262,1263,1264,1268,1269],{},"This series is somewhat of a sequel to the article ",[318,1265,1267],{"href":1266},"\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. ",[1270,1271,1272],"em",{},"You will learn how the most popular component libraries are constructed behind the scenes and how to create your own.",[1274,1275],"callout-read-more",{"id":1276},"f9754148-40bd-4df2-a144-f686e894b200",[10,1278,1279],{},"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,1281,1282,1283,1288,1289,44],{},"That's understandable. While ",[318,1284,1287],{"href":1285,"rel":1286},"https:\u002F\u002Fgithub.com\u002Funjs\u002Funbuild",[322],"unbuild"," is a powerful tool, it cannot match the flexibility, plugin ecosystem, and adoption of ",[318,1290,622],{"href":1291,"rel":1292},"https:\u002F\u002Fvite.dev\u002F",[322],[70,1294,1296],{"id":1295},"what-to-expect","What to expect",[10,1298,1299],{},"Throughout this series, we will address the following topics:",[331,1301,1302,1314,1348,1364,1381,1387,1399],{},[334,1303,1304,1307,1308,1313],{},[14,1305,1306],{},"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 ",[318,1309,1312],{"href":1310,"rel":1311},"https:\u002F\u002Feslint.org\u002F",[322],"ESLint"," to ensure code consistency.",[334,1315,1316,1319,1320,1324,1325,1330,1331,1336,1337,1342,1343,44],{},[14,1317,1318],{},"Building a First Component with Vue.js and Tailwind CSS",": We'll create our first component with ",[318,1321,33],{"href":1322,"rel":1323},"https:\u002F\u002Fvuejs.org\u002F",[322],", ",[318,1326,1329],{"href":1327,"rel":1328},"https:\u002F\u002Ftailwindcss.com\u002F",[322],"Tailwind CSS",", and ",[318,1332,1335],{"href":1333,"rel":1334},"https:\u002F\u002Fwww.tailwind-variants.org\u002F",[322],"Tailwind Variants"," using the most advanced and powerful techniques employed in popular component libraries like ",[318,1338,1341],{"href":1339,"rel":1340},"https:\u002F\u002Fwww.radix-vue.com\u002F",[322],"Radix Vue"," and ",[318,1344,1347],{"href":1345,"rel":1346},"https:\u002F\u002Fui.nuxt.com\u002F",[322],"Nuxt UI",[334,1349,1350,1352,1353,1357,1358,1363],{},[14,1351,5],{},": We'll enhance our development experience by adding ",[318,1354,16],{"href":1355,"rel":1356},"https:\u002F\u002Fwww.typescriptlang.org\u002F",[322]," to our component library and configuring ",[318,1359,1362],{"href":1360,"rel":1361},"https:\u002F\u002Fwww.typescriptlang.org\u002Ftsconfig",[322],"TSConfig"," to ensure that our components are typed correctly and that we can take full advantage of TypeScript's features.",[334,1365,1366,1369,1370,1342,1375,1380],{},[14,1367,1368],{},"Automatic Component Testing with Vitest and Testing Library",": We'll write tests for our components using ",[318,1371,1374],{"href":1372,"rel":1373},"https:\u002F\u002Fvitest.dev\u002Fguide\u002F",[322],"Vitest",[318,1376,1379],{"href":1377,"rel":1378},"https:\u002F\u002Ftesting-library.com\u002F",[322],"Testing Library"," to ensure that our components function as expected. This is crucial for a professional component library that remains reliable over time.",[334,1382,1383,1386],{},[14,1384,1385],{},"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.",[334,1388,1389,1392,1393,1398],{},[14,1390,1391],{},"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 ",[318,1394,1397],{"href":1395,"rel":1396},"https:\u002F\u002Fhistoire.dev\u002F",[322],"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.",[334,1400,1401,1404,1405,1410,1411,1416],{},[14,1402,1403],{},"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 ",[318,1406,1409],{"href":1407,"rel":1408},"https:\u002F\u002Fgithub.com\u002Funplugin\u002Funplugin-vue-components",[322],"Unplugin Vue Components"," and a ",[318,1412,1415],{"href":1413,"rel":1414},"https:\u002F\u002Fnuxt.com\u002Fdocs\u002Fguide\u002Fgoing-further\u002Fmodules",[322],"Nuxt module"," to utilize our components in a Nuxt application.",[10,1418,1419],{},"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? 😎",[70,1421,1423],{"id":1422},"chapters","Chapters",[1425,1426],"series-chapters-list",{"className":1427},[1428,1429],"mx-auto","max-w-5xl",{"title":87,"searchDepth":180,"depth":180,"links":1431},[1432,1433],{"id":1295,"depth":180,"text":1296},{"id":1422,"depth":180,"text":1423},"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":1437,"repository":1438},"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":1252,"description":1435},{"loc":1441},"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.",[1448,1449,1450],"vue","vite","component library","2VSSnBlkuSLlt05n9MySLBFt6vBkgd7691eX-TK2cTs",[1453,1457,1461,1462,1466,1470,1474],{"contentId":1454,"title":1306,"description":1455,"path":1456,"part":94,"github":1240,"topics":1240},"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":1458,"title":1318,"description":1459,"path":1460,"part":180,"github":1240,"topics":1240},"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":1236,"title":5,"description":1238,"path":1242,"part":196,"github":1240,"topics":1240},{"contentId":1463,"title":1368,"description":1464,"path":1465,"part":209,"github":1240,"topics":1240},"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":1467,"title":1385,"description":1468,"path":1469,"part":216,"github":1240,"topics":1240},"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":1471,"title":1391,"description":1472,"path":1473,"part":231,"github":1240,"topics":1240},"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":1475,"title":1403,"description":1476,"path":1477,"part":237,"github":1240,"topics":1240},"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",1795016694618]