[{"data":1,"prerenderedAt":2560},["ShallowReactive",2],{"series-\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Foptimize-your-vitepress-blog-architecture-design":3,"series-context-\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch":2254},{"id":4,"title":5,"body":6,"contentId":2240,"date":2241,"description":2242,"extension":538,"github":2243,"meetTheInstructor":2245,"meta":2246,"navigation":121,"part":125,"path":2247,"rawbody":2248,"robots":2245,"schemaOrg":2245,"seo":2249,"seriesSlug":2250,"sitemap":2251,"stem":2252,"subtitle":2245,"topics":2245,"__hash__":2253},"series\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Foptimize-your-vitepress-blog-architecture-design.md","Optimize Your VitePress Blog's Architecture Design",{"type":7,"value":8,"toc":2226},"minimark",[9,22,32,49,64,87,169,180,193,206,249,261,266,276,283,327,414,428,433,442,452,475,494,511,531,534,571,580,726,738,750,754,765,774,785,792,797,813,841,858,865,954,967,986,989,992,1012,1025,1331,1354,1370,1383,1394,1402,1469,1475,1495,1511,1518,1726,1729,1733,1736,1751,1754,1770,1775,2050,2053,2099,2111,2133,2137,2147,2205,2222],[10,11,12,13,17,18,21],"p",{},"In the preceding article, we initialized our ",[14,15,16],"strong",{},"VitePress project"," and examined its structure. We also began incorporating our custom theme. Today, we will further progress by defining the ",[14,19,20],{},"blog's architecture"," and design to ensure it remains manageable and scalable over time.",[23,24,26,27,31],"h2",{"id":25},"the-src-directory","The ",[28,29,30],"code",{},"src"," directory",[10,33,34,35,38,39,41,42,44,45,48],{},"To begin, we will relocate our project's ",[14,36,37],{},"source files"," to a designated ",[28,40,30],{}," directory. This approach prevents cluttering the root directory with ",[14,43,37],{}," and avoids including unwanted files like ",[28,46,47],{},"README.md"," in our project's pages.",[10,50,51,52,55,56,59,60,63],{},"What constitutes our source files? Specifically, is the theme a source file? The answer is no. As we're developing a ",[14,53,54],{},"content-centric website",", only markdown and public files are considered source files. Everything related to the theme is part of the VitePress ",[14,57,58],{},"configuration"," and will reside in the ",[28,61,62],{},".vitepress"," directory.",[10,65,66,67,76,77,80,81,83,84,86],{},"To modify the source directory, we need to update the ",[68,69,73],"a",{"href":70,"rel":71},"https:\u002F\u002Fvitepress.dev\u002Freference\u002Fsite-config#srcdir",[72],"nofollow",[28,74,75],{},"srcDir"," option in the ",[28,78,79],{},"config.mts"," file located in the ",[28,82,62],{}," directory. Here is the revised content of the ",[28,85,79],{}," file:",[88,89,94],"pre",{"className":90,"code":91,"filename":79,"language":92,"meta":93,"style":93},"language-ts shiki shiki-themes github-light github-light github-dark","import { defineConfig } from 'vitepress'\n\nexport default defineConfig({\n  srcDir: 'src',\n\n  \u002F\u002F ...\n})\n","ts","",[28,95,96,116,123,139,151,156,163],{"__ignoreMap":93},[97,98,101,105,109,112],"span",{"class":99,"line":100},"line",1,[97,102,104],{"class":103},"s8jYJ","import",[97,106,108],{"class":107},"sxrX7"," { defineConfig } ",[97,110,111],{"class":103},"from",[97,113,115],{"class":114},"sIIMD"," 'vitepress'\n",[97,117,119],{"class":99,"line":118},2,[97,120,122],{"emptyLinePlaceholder":121},true,"\n",[97,124,126,129,132,136],{"class":99,"line":125},3,[97,127,128],{"class":103},"export",[97,130,131],{"class":103}," default",[97,133,135],{"class":134},"snPdu"," defineConfig",[97,137,138],{"class":107},"({\n",[97,140,142,145,148],{"class":99,"line":141},4,[97,143,144],{"class":107},"  srcDir: ",[97,146,147],{"class":114},"'src'",[97,149,150],{"class":107},",\n",[97,152,154],{"class":99,"line":153},5,[97,155,122],{"emptyLinePlaceholder":121},[97,157,159],{"class":99,"line":158},6,[97,160,162],{"class":161},"sCsY4","  \u002F\u002F ...\n",[97,164,166],{"class":99,"line":165},7,[97,167,168],{"class":107},"})\n",[10,170,171,172,175,176,179],{},"This option informs ",[14,173,174],{},"VitePress"," where our ",[14,177,178],{},"markdown pages"," are stored relative to the project root. In our instance, the project root is the repository's root.",[10,181,26,182,184,185,188,189,192],{},[28,183,30],{}," directory will also encompass a ",[28,186,187],{},"public"," directory, where ",[14,190,191],{},"static assets"," like images, fonts, and other unaltered files will be stored.",[194,195,198],"callout",{"color":196,"icon":197},"info","i-ph-info-duotone",[10,199,26,200,202,203,205],{},[28,201,187],{}," directory associates with the site's root and is not processed by VitePress. Therefore, files in the ",[28,204,187],{}," directory will be copied to the root of the generated site without any transformation.",[88,207,212],{"className":208,"code":209,"filename":210,"language":211,"meta":93,"style":93},"language-txt shiki shiki-themes github-light github-light github-dark",".\n├── .vitepress\n│   └── config.mts\n├── src\n│   ├── public\n│   └── index.md\n└── package.json\n","Example","txt",[28,213,214,219,224,229,234,239,244],{"__ignoreMap":93},[97,215,216],{"class":99,"line":100},[97,217,218],{},".\n",[97,220,221],{"class":99,"line":118},[97,222,223],{},"├── .vitepress\n",[97,225,226],{"class":99,"line":125},[97,227,228],{},"│   └── config.mts\n",[97,230,231],{"class":99,"line":141},[97,232,233],{},"├── src\n",[97,235,236],{"class":99,"line":153},[97,237,238],{},"│   ├── public\n",[97,240,241],{"class":99,"line":158},[97,242,243],{},"│   └── index.md\n",[97,245,246],{"class":99,"line":165},[97,247,248],{},"└── package.json\n",[10,250,251,252,255,256,258,259,63],{},"This structure is significantly cleaner and more organized. If we aim to write a ",[14,253,254],{},"blog post",", we simply open the ",[28,257,30],{}," directory, and if we desire to update our theme, we access the ",[28,260,62],{},[23,262,26,264,31],{"id":263},"the-vitepress-directory",[28,265,62],{},[10,267,268,269,271,272,275],{},"Regarding the ",[28,270,62],{}," directory, we can create subdirectories to aid in structuring our ",[14,273,274],{},"theme",", maintaining simplicity akin to a standard Vite + Vue project.",[10,277,278,279,282],{},"Under ",[28,280,281],{},".vitepress\u002Ftheme",", we will establish the following directories:",[284,285,286,293,299,309,315,321],"ul",{},[287,288,289,292],"li",{},[28,290,291],{},"components",": Contains all the Vue components used in the theme.",[287,294,295,298],{},[28,296,297],{},"composables",": Contains all the Vue composables utilized in the theme.",[287,300,301,304,305,308],{},[28,302,303],{},"pages",": Contains all the Vue components employed as pages in the ",[28,306,307],{},"Layout.vue"," component.",[287,310,311,314],{},[28,312,313],{},"styles",": Contains all the CSS files applied in the theme.",[287,316,317,320],{},[28,318,319],{},"types",": Contains all the TypeScript types utilized in the theme.",[287,322,323,326],{},[28,324,325],{},"utils",": Contains all the utility functions used in the theme.",[88,328,330],{"className":208,"code":329,"filename":307,"language":211,"meta":93,"style":93},".\n├── .vitepress\n│   ├── theme\n│   │   ├── components\n│   │   ├── composables\n│   │   ├── pages\n│   │   ├── styles\n│   │   ├── types\n│   │   ├── utils\n│   │   ├── index.ts\n│   │   └── Layout.vue\n│   └── config.mts\n├── src\n│   ├── public\n│   └── index.md\n└── package.json\n",[28,331,332,336,340,345,350,355,360,365,371,377,383,389,394,399,404,409],{"__ignoreMap":93},[97,333,334],{"class":99,"line":100},[97,335,218],{},[97,337,338],{"class":99,"line":118},[97,339,223],{},[97,341,342],{"class":99,"line":125},[97,343,344],{},"│   ├── theme\n",[97,346,347],{"class":99,"line":141},[97,348,349],{},"│   │   ├── components\n",[97,351,352],{"class":99,"line":153},[97,353,354],{},"│   │   ├── composables\n",[97,356,357],{"class":99,"line":158},[97,358,359],{},"│   │   ├── pages\n",[97,361,362],{"class":99,"line":165},[97,363,364],{},"│   │   ├── styles\n",[97,366,368],{"class":99,"line":367},8,[97,369,370],{},"│   │   ├── types\n",[97,372,374],{"class":99,"line":373},9,[97,375,376],{},"│   │   ├── utils\n",[97,378,380],{"class":99,"line":379},10,[97,381,382],{},"│   │   ├── index.ts\n",[97,384,386],{"class":99,"line":385},11,[97,387,388],{},"│   │   └── Layout.vue\n",[97,390,392],{"class":99,"line":391},12,[97,393,228],{},[97,395,397],{"class":99,"line":396},13,[97,398,233],{},[97,400,402],{"class":99,"line":401},14,[97,403,238],{},[97,405,407],{"class":99,"line":406},15,[97,408,243],{},[97,410,412],{"class":99,"line":411},16,[97,413,248],{},[10,415,416,417,420,421,424,425,427],{},"This structure closely mirrors what many ",[14,418,419],{},"Vue developers"," are accustomed to, which is advantageous! It eliminates the need to learn a new project structure while utilizing VitePress. If you're familiar with structuring a ",[14,422,423],{},"Vue project",", you already know how to structure a ",[14,426,16],{},". 👌",[23,429,26,431,31],{"id":430},"the-pages-directory",[28,432,303],{},[10,434,435,436,438,439,441],{},"I acknowledge this might seem confusing. I mentioned earlier that VitePress features a minimal router, and routes are generated from the ",[28,437,30],{}," directory's structure. So, what do these ",[28,440,303],{}," imply?",[10,443,444,445,447,448,451],{},"VitePress follows the convention of using ",[28,446,307],{}," as the entry point for the Vue application. Given this scenario, having a ",[28,449,450],{},"layouts"," directory would imply that a layout utilizes a layout, which seems peculiar to me.",[10,453,454,455,457,458,461,462,464,465,468,469,471,472,474],{},"Renaming ",[28,456,307],{}," to ",[28,459,460],{},"App.vue"," might be an option, yet I find it less appealing. I prefer retaining the ",[28,463,307],{}," name as it's a VitePress convention. Moreover, as VitePress doesn't have a router, we can't use a ",[28,466,467],{}," RouterView"," component to render the layout and the page. This implies that ",[28,470,307],{}," and ",[28,473,460],{}," serve different purposes.",[10,476,477,478,482,483,486,487,486,490,493],{},"Ultimately, establishing a ",[14,479,480,31],{},[28,481,303],{}," seemed the most logical decision. Within this directory, we include Vue components such as ",[28,484,485],{},"NotFound.vue",", ",[28,488,489],{},"Blog\u002FBlogIndex.vue",[28,491,492],{},"Blog\u002FBlogPost.vue",", etc., forming a file routing system.",[194,495,496],{"color":196,"icon":197},[10,497,26,498,500,501,504,505,507,508,510],{},[28,499,303],{}," directory is my approach to organizing the project. It's not mandated by VitePress. Any ",[28,502,503],{},".vue"," files could reside in the ",[28,506,291],{}," or ",[28,509,450],{}," directory. Feel free to customize the structure according to your preferences.",[10,512,513,514,516,517,520,521,524,525,527,528,530],{},"In conclusion, we'll use ",[28,515,307],{}," to route our Markdown files to the appropriate ",[14,518,519],{},"page component",". To accomplish this, we'll use the ",[28,522,523],{},"layout"," key in the frontmatter of our Markdown files. This key facilitates importing the correct ",[14,526,519],{}," in the ",[28,529,307],{}," file.",[10,532,533],{},"Consider the following Markdown file:",[88,535,539],{"className":536,"code":537,"filename":307,"language":538,"meta":93,"style":93},"language-md shiki shiki-themes github-light github-light github-dark","---\nlayout: blog-post\n---\n\n# Hello, World!\n","md",[28,540,541,546,557,561,565],{"__ignoreMap":93},[97,542,543],{"class":99,"line":100},[97,544,545],{"class":107},"---\n",[97,547,548,551,554],{"class":99,"line":118},[97,549,523],{"class":550},"sovSZ",[97,552,553],{"class":107},": ",[97,555,556],{"class":114},"blog-post\n",[97,558,559],{"class":99,"line":125},[97,560,545],{"class":107},[97,562,563],{"class":99,"line":141},[97,564,122],{"emptyLinePlaceholder":121},[97,566,567],{"class":99,"line":153},[97,568,570],{"class":569},"syb_3","# Hello, World!\n",[10,572,573,574,576,577,579],{},"In the ",[28,575,307],{}," file, we can render the ",[28,578,492],{}," component as follows:",[88,581,585],{"className":582,"code":583,"filename":492,"language":584,"meta":93,"style":93},"language-vue shiki shiki-themes github-light github-light github-dark","\u003Cscript lang=\"ts\" setup>\nimport { useData } from 'vitepress'\n\nconst { frontmatter } = useData() \u002F\u002F This is the frontmatter of the current Markdown file\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003CBlogPost v-if=\"frontmatter.layout === 'blog-post'\" \u002F>\n\n  \u003CContent v-else \u002F> \u002F\u002F Just render the content of the Markdown file\n\u003C\u002Ftemplate>\n","vue",[28,586,587,610,621,625,651,660,664,673,701,705,718],{"__ignoreMap":93},[97,588,589,592,595,598,601,604,607],{"class":99,"line":100},[97,590,591],{"class":107},"\u003C",[97,593,594],{"class":550},"script",[97,596,597],{"class":134}," lang",[97,599,600],{"class":107},"=",[97,602,603],{"class":114},"\"ts\"",[97,605,606],{"class":134}," setup",[97,608,609],{"class":107},">\n",[97,611,612,614,617,619],{"class":99,"line":118},[97,613,104],{"class":103},[97,615,616],{"class":107}," { useData } ",[97,618,111],{"class":103},[97,620,115],{"class":114},[97,622,623],{"class":99,"line":125},[97,624,122],{"emptyLinePlaceholder":121},[97,626,627,630,633,637,640,642,645,648],{"class":99,"line":141},[97,628,629],{"class":103},"const",[97,631,632],{"class":107}," { ",[97,634,636],{"class":635},"sBjJW","frontmatter",[97,638,639],{"class":107}," } ",[97,641,600],{"class":103},[97,643,644],{"class":134}," useData",[97,646,647],{"class":107},"() ",[97,649,650],{"class":161},"\u002F\u002F This is the frontmatter of the current Markdown file\n",[97,652,653,656,658],{"class":99,"line":153},[97,654,655],{"class":107},"\u003C\u002F",[97,657,594],{"class":550},[97,659,609],{"class":107},[97,661,662],{"class":99,"line":158},[97,663,122],{"emptyLinePlaceholder":121},[97,665,666,668,671],{"class":99,"line":165},[97,667,591],{"class":107},[97,669,670],{"class":550},"template",[97,672,609],{"class":107},[97,674,675,678,681,684,686,689,692,695,698],{"class":99,"line":367},[97,676,677],{"class":107},"  \u003C",[97,679,680],{"class":550},"BlogPost",[97,682,683],{"class":103}," v-if",[97,685,600],{"class":107},[97,687,688],{"class":114},"\"",[97,690,691],{"class":107},"frontmatter.layout ",[97,693,694],{"class":103},"===",[97,696,697],{"class":114}," 'blog-post'\"",[97,699,700],{"class":107}," \u002F>\n",[97,702,703],{"class":99,"line":373},[97,704,122],{"emptyLinePlaceholder":121},[97,706,707,709,712,715],{"class":99,"line":379},[97,708,677],{"class":107},[97,710,711],{"class":550},"Content",[97,713,714],{"class":103}," v-else",[97,716,717],{"class":107}," \u002F> \u002F\u002F Just render the content of the Markdown file\n",[97,719,720,722,724],{"class":99,"line":385},[97,721,655],{"class":107},[97,723,670],{"class":550},[97,725,609],{"class":107},[10,727,728,729,733,734,737],{},"This approach enables a dynamic routing system without an actual router. Meanwhile, ",[14,730,731],{},[28,732,307],{}," remains the entry point of the ",[14,735,736],{},"Vue application",".",[194,739,740],{"color":196,"icon":197},[10,741,742,743,746,747,737],{},"If anything isn't clear, don't worry. We'll apply this in the upcoming articles when introducing ",[14,744,745],{},"blog posts"," and the ",[14,748,749],{},"blog list",[23,751,753],{"id":752},"configuring-unplugin-vue-components","Configuring Unplugin Vue Components",[10,755,756,757,759,760,737],{},"In the previous code snippet, we used the ",[28,758,680],{}," component without importing it. This magic becomes feasible with the help of ",[68,761,764],{"href":762,"rel":763},"https:\u002F\u002Fgithub.com\u002Funplugin\u002Funplugin-vue-components",[72],"Unplugin Vue Components",[194,766,767],{"color":196,"icon":197},[10,768,769,770,773],{},"This step is entirely optional, and you can skip it if desired. For me, it's an excellent way to maintain clean code, and as a ",[14,771,772],{},"Nuxt user",", I have a slight preference for this method. 😅",[10,775,776,777,780,781,784],{},"Behind the scenes, this plugin for Vite scans our files for Vue components as they pass through the Vite pipeline. When it detects a component, it adds the relevant ",[14,778,779],{},"import statement"," at the top of the file. This aligns with Vite's ",[14,782,783],{},"on-demand"," philosophy, ensuring small bundle sizes and allowing component chunking where they are utilized.",[10,786,787,788,791],{},"This plugin seamlessly integrates with TypeScript, ensuring that we do not compromise type checking or ",[14,789,790],{},"auto-completion"," in our IDE.",[793,794,796],"h3",{"id":795},"installing-necessary-dependencies","Installing necessary dependencies",[10,798,799,800,746,803,806,807,812],{},"First, we must install ",[14,801,802],{},"TypeScript",[14,804,805],{},"Node types",". This is essential as the plugin generates a ",[68,808,811],{"href":809,"rel":810},"https:\u002F\u002Fwww.typescriptlang.org\u002Fdocs\u002Fhandbook\u002F2\u002Ftype-declarations.html#dts-files",[72],"declaration file"," containing our components' types.",[88,814,819],{"className":815,"code":816,"filename":817,"language":818,"meta":93,"style":93},"language-bash shiki shiki-themes github-light github-light github-dark","pnpm add -D typescript @types\u002Fnode vue\n","terminal","bash",[28,820,821],{"__ignoreMap":93},[97,822,823,826,829,832,835,838],{"class":99,"line":100},[97,824,825],{"class":134},"pnpm",[97,827,828],{"class":114}," add",[97,830,831],{"class":635}," -D",[97,833,834],{"class":114}," typescript",[97,836,837],{"class":114}," @types\u002Fnode",[97,839,840],{"class":114}," vue\n",[194,842,843],{"color":196,"icon":197},[10,844,845,846,848,849,857],{},"The installation of ",[28,847,584],{}," is required when utilizing pnpm due to its hoisting mechanism. Refer to the ",[68,850,853,856],{"href":851,"rel":852},"https:\u002F\u002Fpnpm.io\u002Fnpmrc#shamefully-hoist",[72],[28,854,855],{},"shamefully-hoist"," option"," for further explanation.",[10,859,860,861,864],{},"Next, a ",[28,862,863],{},"tsconfig.json"," file should be created at the project's root to guide TypeScript's behavior.",[88,866,870],{"className":867,"code":868,"filename":863,"language":869,"meta":93,"style":93},"language-json shiki shiki-themes github-light github-light github-dark","{\n  \"compilerOptions\": {\n    \"target\": \"ESNext\",\n    \"module\": \"ESNext\",\n    \"moduleResolution\": \"Bundler\",\n    \"strict\": true\n  },\n  \"include\": [\".\u002F.vitepress\u002F**\u002F*\"]\n}\n","json",[28,871,872,877,885,897,908,920,930,935,949],{"__ignoreMap":93},[97,873,874],{"class":99,"line":100},[97,875,876],{"class":107},"{\n",[97,878,879,882],{"class":99,"line":118},[97,880,881],{"class":635},"  \"compilerOptions\"",[97,883,884],{"class":107},": {\n",[97,886,887,890,892,895],{"class":99,"line":125},[97,888,889],{"class":635},"    \"target\"",[97,891,553],{"class":107},[97,893,894],{"class":114},"\"ESNext\"",[97,896,150],{"class":107},[97,898,899,902,904,906],{"class":99,"line":141},[97,900,901],{"class":635},"    \"module\"",[97,903,553],{"class":107},[97,905,894],{"class":114},[97,907,150],{"class":107},[97,909,910,913,915,918],{"class":99,"line":153},[97,911,912],{"class":635},"    \"moduleResolution\"",[97,914,553],{"class":107},[97,916,917],{"class":114},"\"Bundler\"",[97,919,150],{"class":107},[97,921,922,925,927],{"class":99,"line":158},[97,923,924],{"class":635},"    \"strict\"",[97,926,553],{"class":107},[97,928,929],{"class":635},"true\n",[97,931,932],{"class":99,"line":165},[97,933,934],{"class":107},"  },\n",[97,936,937,940,943,946],{"class":99,"line":367},[97,938,939],{"class":635},"  \"include\"",[97,941,942],{"class":107},": [",[97,944,945],{"class":114},"\".\u002F.vitepress\u002F**\u002F*\"",[97,947,948],{"class":107},"]\n",[97,950,951],{"class":99,"line":373},[97,952,953],{"class":107},"}\n",[10,955,26,956,959,960,962,963,966],{},[28,957,958],{},"@types\u002Fnode"," is automatically incorporated by TypeScript. We include all files within the ",[28,961,62],{}," directory where our TypeScript and Vue components reside. This pattern also imports ",[28,964,965],{},".d.ts"," files, which is crucial for the plugin.",[10,968,969,970,527,973,976,977,471,980,457,983,737],{},"You should also add ",[28,971,972],{},"\"type\": \"module\"",[28,974,975],{},"package.json"," file and modify the extensions of ",[28,978,979],{},"postcss.config.js",[28,981,982],{},"tailwind.config.js",[28,984,985],{},".cjs",[793,987,988],{"id":58},"Configuration",[10,990,991],{},"Finalizing the configuration of the plugin is straightforward:",[993,994,995,1002,1007],"ol",{},[287,996,997,998,1001],{},"Indicate to the plugin the directory where our ",[14,999,1000],{},"Vue components"," reside.",[287,1003,1004,1005,737],{},"Define to the plugin the naming conventions for our ",[14,1006,1000],{},[287,1008,1009,1010,737],{},"Specify to the plugin the location for creating the ",[14,1011,811],{},[10,1013,1014,1015,1017,1018,1020,1021,1024],{},"Given the ",[28,1016,79],{}," file resides within the ",[28,1019,62],{}," directory, there is more configuration than in a standard Vite project where the configuration ",[28,1022,1023],{},"vite.config.ts"," is situated at the project's root.",[88,1026,1028],{"className":90,"code":1027,"filename":1023,"language":92,"meta":93,"style":93},"import { dirname, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport Components from 'unplugin-vue-components\u002Fvite'\nimport { defineConfig } from 'vitepress'\n\nconst currentDir = dirname(fileURLToPath(import.meta.url))\n\nconst componentsDir = resolve(currentDir, 'theme', 'components')\nconst pagesDir = resolve(currentDir, 'theme', 'pages')\n\nexport default defineConfig({\n  \u002F\u002F ...\n\n  vite: {\n    plugins: [\n      Components({\n        dirs: [\n          componentsDir,\n          pagesDir,\n        ],\n        include: [\u002F\\.vue$\u002F, \u002F\\.vue\\?vue\u002F, \u002F\\.md$\u002F],\n        dts: resolve(\n          currentDir,\n          'components.d.ts'\n        ),\n      }),\n    ],\n  },\n})\n",[28,1029,1030,1042,1054,1066,1076,1080,1111,1115,1141,1163,1167,1177,1181,1185,1190,1195,1202,1208,1214,1220,1226,1279,1291,1297,1303,1309,1315,1321,1326],{"__ignoreMap":93},[97,1031,1032,1034,1037,1039],{"class":99,"line":100},[97,1033,104],{"class":103},[97,1035,1036],{"class":107}," { dirname, resolve } ",[97,1038,111],{"class":103},[97,1040,1041],{"class":114}," 'node:path'\n",[97,1043,1044,1046,1049,1051],{"class":99,"line":118},[97,1045,104],{"class":103},[97,1047,1048],{"class":107}," { fileURLToPath } ",[97,1050,111],{"class":103},[97,1052,1053],{"class":114}," 'node:url'\n",[97,1055,1056,1058,1061,1063],{"class":99,"line":125},[97,1057,104],{"class":103},[97,1059,1060],{"class":107}," Components ",[97,1062,111],{"class":103},[97,1064,1065],{"class":114}," 'unplugin-vue-components\u002Fvite'\n",[97,1067,1068,1070,1072,1074],{"class":99,"line":141},[97,1069,104],{"class":103},[97,1071,108],{"class":107},[97,1073,111],{"class":103},[97,1075,115],{"class":114},[97,1077,1078],{"class":99,"line":153},[97,1079,122],{"emptyLinePlaceholder":121},[97,1081,1082,1084,1087,1090,1093,1096,1099,1101,1103,1105,1108],{"class":99,"line":158},[97,1083,629],{"class":103},[97,1085,1086],{"class":635}," currentDir",[97,1088,1089],{"class":103}," =",[97,1091,1092],{"class":134}," dirname",[97,1094,1095],{"class":107},"(",[97,1097,1098],{"class":134},"fileURLToPath",[97,1100,1095],{"class":107},[97,1102,104],{"class":103},[97,1104,737],{"class":107},[97,1106,1107],{"class":635},"meta",[97,1109,1110],{"class":107},".url))\n",[97,1112,1113],{"class":99,"line":165},[97,1114,122],{"emptyLinePlaceholder":121},[97,1116,1117,1119,1122,1124,1127,1130,1133,1135,1138],{"class":99,"line":367},[97,1118,629],{"class":103},[97,1120,1121],{"class":635}," componentsDir",[97,1123,1089],{"class":103},[97,1125,1126],{"class":134}," resolve",[97,1128,1129],{"class":107},"(currentDir, ",[97,1131,1132],{"class":114},"'theme'",[97,1134,486],{"class":107},[97,1136,1137],{"class":114},"'components'",[97,1139,1140],{"class":107},")\n",[97,1142,1143,1145,1148,1150,1152,1154,1156,1158,1161],{"class":99,"line":373},[97,1144,629],{"class":103},[97,1146,1147],{"class":635}," pagesDir",[97,1149,1089],{"class":103},[97,1151,1126],{"class":134},[97,1153,1129],{"class":107},[97,1155,1132],{"class":114},[97,1157,486],{"class":107},[97,1159,1160],{"class":114},"'pages'",[97,1162,1140],{"class":107},[97,1164,1165],{"class":99,"line":379},[97,1166,122],{"emptyLinePlaceholder":121},[97,1168,1169,1171,1173,1175],{"class":99,"line":385},[97,1170,128],{"class":103},[97,1172,131],{"class":103},[97,1174,135],{"class":134},[97,1176,138],{"class":107},[97,1178,1179],{"class":99,"line":391},[97,1180,162],{"class":161},[97,1182,1183],{"class":99,"line":396},[97,1184,122],{"emptyLinePlaceholder":121},[97,1186,1187],{"class":99,"line":401},[97,1188,1189],{"class":107},"  vite: {\n",[97,1191,1192],{"class":99,"line":406},[97,1193,1194],{"class":107},"    plugins: [\n",[97,1196,1197,1200],{"class":99,"line":411},[97,1198,1199],{"class":134},"      Components",[97,1201,138],{"class":107},[97,1203,1205],{"class":99,"line":1204},17,[97,1206,1207],{"class":107},"        dirs: [\n",[97,1209,1211],{"class":99,"line":1210},18,[97,1212,1213],{"class":107},"          componentsDir,\n",[97,1215,1217],{"class":99,"line":1216},19,[97,1218,1219],{"class":107},"          pagesDir,\n",[97,1221,1223],{"class":99,"line":1222},20,[97,1224,1225],{"class":107},"        ],\n",[97,1227,1229,1232,1235,1239,1242,1245,1247,1250,1253,1255,1257,1260,1262,1264,1266,1268,1270,1272,1274,1276],{"class":99,"line":1228},21,[97,1230,1231],{"class":107},"        include: [",[97,1233,1234],{"class":114},"\u002F",[97,1236,1238],{"class":1237},"sujWL","\\.",[97,1240,584],{"class":1241},"s3JiQ",[97,1243,1244],{"class":103},"$",[97,1246,1234],{"class":114},[97,1248,1249],{"class":107},",",[97,1251,1252],{"class":114}," \u002F",[97,1254,1238],{"class":1237},[97,1256,584],{"class":1241},[97,1258,1259],{"class":1237},"\\?",[97,1261,584],{"class":1241},[97,1263,1234],{"class":114},[97,1265,1249],{"class":107},[97,1267,1252],{"class":114},[97,1269,1238],{"class":1237},[97,1271,538],{"class":1241},[97,1273,1244],{"class":103},[97,1275,1234],{"class":114},[97,1277,1278],{"class":107},"],\n",[97,1280,1282,1285,1288],{"class":99,"line":1281},22,[97,1283,1284],{"class":107},"        dts: ",[97,1286,1287],{"class":134},"resolve",[97,1289,1290],{"class":107},"(\n",[97,1292,1294],{"class":99,"line":1293},23,[97,1295,1296],{"class":107},"          currentDir,\n",[97,1298,1300],{"class":99,"line":1299},24,[97,1301,1302],{"class":114},"          'components.d.ts'\n",[97,1304,1306],{"class":99,"line":1305},25,[97,1307,1308],{"class":107},"        ),\n",[97,1310,1312],{"class":99,"line":1311},26,[97,1313,1314],{"class":107},"      }),\n",[97,1316,1318],{"class":99,"line":1317},27,[97,1319,1320],{"class":107},"    ],\n",[97,1322,1324],{"class":99,"line":1323},28,[97,1325,934],{"class":107},[97,1327,1329],{"class":99,"line":1328},29,[97,1330,168],{"class":107},[10,1332,26,1333,1336,1337,471,1340,1343,1344,1346,1347,1349,1350,1353],{},[28,1334,1335],{},"dirs"," option directs the plugin to where our components are located. In our context, we have two directories: ",[28,1338,1339],{},"theme\u002Fpages",[28,1341,1342],{},"theme\u002Fcomponents",", relative to the ",[28,1345,79],{}," file. This distinction matters because the process initiates in the project's root, but the configuration lies within the ",[28,1348,62],{}," directory. It prevents the use of ",[28,1351,1352],{},"..\u002F..\u002F"," in paths.",[10,1355,26,1356,1359,1360,471,1362,1365,1366,1369],{},[28,1357,1358],{},"include"," option specifies the file extensions that should be scanned to add import statements. We include ",[28,1361,503],{},[28,1363,1364],{},".md"," files as we might have Vue components in ",[14,1367,1368],{},"Markdown files"," without the need for explicit imports, which is a fantastic feature.",[10,1371,26,1372,1375,1376,1379,1380,1382],{},[28,1373,1374],{},"dts"," option guides the plugin on where to create the declaration file. We desire to create the ",[28,1377,1378],{},"components.d.ts"," file within the ",[28,1381,62],{}," directory's root. This declaration file aids our IDE and TypeScript in providing auto-completion and type checking, even when components are not explicitly imported.",[10,1384,1385,1386,1388,1389,1393],{},"When we launch our development server, we should verify the plugin's functionality by examining the ",[28,1387,1378],{}," file. Initially, this file might not feature any components as we don't have any. Creating a temporary component will allow observation of the changes and requires a development server restart. Use ",[1390,1391,1392],"kbd",{},"r"," to restart the server.",[194,1395,1396],{"color":196,"icon":197},[10,1397,1398,1399],{},"The current setup will not function as described, and it's normal. ",[14,1400,1401],{},"Continue reading to understand why and see the final configuration.",[88,1403,1405],{"className":90,"code":1404,"filename":1378,"language":92,"meta":93,"style":93},"\u002F\u002F Generated by unplugin-vue-components\n\u002F\u002F Read more: https:\u002F\u002Fgithub.com\u002Fvuejs\u002Fcore\u002Fpull\u002F3399\nexport {}\n\n\u002F* prettier-ignore *\u002F\ndeclare module 'vue' {\n  export interface GlobalComponents {\n  }\n}\n",[28,1406,1407,1412,1417,1424,1428,1433,1447,1460,1465],{"__ignoreMap":93},[97,1408,1409],{"class":99,"line":100},[97,1410,1411],{"class":161},"\u002F\u002F Generated by unplugin-vue-components\n",[97,1413,1414],{"class":99,"line":118},[97,1415,1416],{"class":161},"\u002F\u002F Read more: https:\u002F\u002Fgithub.com\u002Fvuejs\u002Fcore\u002Fpull\u002F3399\n",[97,1418,1419,1421],{"class":99,"line":125},[97,1420,128],{"class":103},[97,1422,1423],{"class":107}," {}\n",[97,1425,1426],{"class":99,"line":141},[97,1427,122],{"emptyLinePlaceholder":121},[97,1429,1430],{"class":99,"line":153},[97,1431,1432],{"class":161},"\u002F* prettier-ignore *\u002F\n",[97,1434,1435,1438,1441,1444],{"class":99,"line":158},[97,1436,1437],{"class":103},"declare",[97,1439,1440],{"class":103}," module",[97,1442,1443],{"class":114}," 'vue'",[97,1445,1446],{"class":107}," {\n",[97,1448,1449,1452,1455,1458],{"class":99,"line":165},[97,1450,1451],{"class":103},"  export",[97,1453,1454],{"class":103}," interface",[97,1456,1457],{"class":134}," GlobalComponents",[97,1459,1446],{"class":107},[97,1461,1462],{"class":99,"line":367},[97,1463,1464],{"class":107},"  }\n",[97,1466,1467],{"class":99,"line":373},[97,1468,953],{"class":107},[10,1470,1471,1472,530],{},"This file is generated by the plugin, should remain unchanged manually, and should be added to the ",[28,1473,1474],{},".gitignore",[88,1476,1478],{"className":208,"code":1477,"filename":210,"language":211,"meta":93,"style":93},"node_modules\ncache\ncomponents.d.ts\n",[28,1479,1480,1485,1490],{"__ignoreMap":93},[97,1481,1482],{"class":99,"line":100},[97,1483,1484],{},"node_modules\n",[97,1486,1487],{"class":99,"line":118},[97,1488,1489],{},"cache\n",[97,1491,1492],{"class":99,"line":125},[97,1493,1494],{},"components.d.ts\n",[10,1496,1497,1498,1501,1502,1504,1505,1507,1508,1510],{},"However, the present setup does not work due to limitations originating from Vite. Underneath, the plugin connects to the Vite files watcher, meaning it only responds to files and directories monitored by Vite. Vite, by default, watches only the ",[28,1499,1500],{},"root"," directory specified by the ",[28,1503,75],{}," of the ",[28,1506,79],{}," file. Consequently, files and directories within the ",[28,1509,62],{}," directory remain undetected by Vite and the plugin.",[10,1512,1513,1514,1517],{},"To address this, we must instruct Vite to monitor the directory where our ",[14,1515,1516],{},"Vue components and pages"," reside. This is achieved by devising a compact plugin to update Vite's watcher configuration:",[88,1519,1521],{"className":90,"code":1520,"filename":79,"language":92,"meta":93,"style":93},"import { dirname, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { defineConfig } from 'vitepress'\n\nconst currentDir = dirname(fileURLToPath(import.meta.url))\n\nconst componentsDir = resolve(currentDir, 'theme', 'components')\nconst pagesDir = resolve(currentDir, 'theme', 'pages')\n\nexport default defineConfig({\n  srcDir: 'src',\n\n  vite: {\n    plugins: [\n      {\n        name: 'watcher',\n        configureServer(server) {\n          server.watcher.add([componentsDir, pagesDir])\n        },\n      },\n      \u002F\u002F ...\n    ],\n  },\n})\n",[28,1522,1523,1533,1543,1553,1557,1581,1585,1605,1625,1629,1639,1647,1651,1655,1659,1664,1674,1688,1699,1704,1709,1714,1718,1722],{"__ignoreMap":93},[97,1524,1525,1527,1529,1531],{"class":99,"line":100},[97,1526,104],{"class":103},[97,1528,1036],{"class":107},[97,1530,111],{"class":103},[97,1532,1041],{"class":114},[97,1534,1535,1537,1539,1541],{"class":99,"line":118},[97,1536,104],{"class":103},[97,1538,1048],{"class":107},[97,1540,111],{"class":103},[97,1542,1053],{"class":114},[97,1544,1545,1547,1549,1551],{"class":99,"line":125},[97,1546,104],{"class":103},[97,1548,108],{"class":107},[97,1550,111],{"class":103},[97,1552,115],{"class":114},[97,1554,1555],{"class":99,"line":141},[97,1556,122],{"emptyLinePlaceholder":121},[97,1558,1559,1561,1563,1565,1567,1569,1571,1573,1575,1577,1579],{"class":99,"line":153},[97,1560,629],{"class":103},[97,1562,1086],{"class":635},[97,1564,1089],{"class":103},[97,1566,1092],{"class":134},[97,1568,1095],{"class":107},[97,1570,1098],{"class":134},[97,1572,1095],{"class":107},[97,1574,104],{"class":103},[97,1576,737],{"class":107},[97,1578,1107],{"class":635},[97,1580,1110],{"class":107},[97,1582,1583],{"class":99,"line":158},[97,1584,122],{"emptyLinePlaceholder":121},[97,1586,1587,1589,1591,1593,1595,1597,1599,1601,1603],{"class":99,"line":165},[97,1588,629],{"class":103},[97,1590,1121],{"class":635},[97,1592,1089],{"class":103},[97,1594,1126],{"class":134},[97,1596,1129],{"class":107},[97,1598,1132],{"class":114},[97,1600,486],{"class":107},[97,1602,1137],{"class":114},[97,1604,1140],{"class":107},[97,1606,1607,1609,1611,1613,1615,1617,1619,1621,1623],{"class":99,"line":367},[97,1608,629],{"class":103},[97,1610,1147],{"class":635},[97,1612,1089],{"class":103},[97,1614,1126],{"class":134},[97,1616,1129],{"class":107},[97,1618,1132],{"class":114},[97,1620,486],{"class":107},[97,1622,1160],{"class":114},[97,1624,1140],{"class":107},[97,1626,1627],{"class":99,"line":373},[97,1628,122],{"emptyLinePlaceholder":121},[97,1630,1631,1633,1635,1637],{"class":99,"line":379},[97,1632,128],{"class":103},[97,1634,131],{"class":103},[97,1636,135],{"class":134},[97,1638,138],{"class":107},[97,1640,1641,1643,1645],{"class":99,"line":385},[97,1642,144],{"class":107},[97,1644,147],{"class":114},[97,1646,150],{"class":107},[97,1648,1649],{"class":99,"line":391},[97,1650,122],{"emptyLinePlaceholder":121},[97,1652,1653],{"class":99,"line":396},[97,1654,1189],{"class":107},[97,1656,1657],{"class":99,"line":401},[97,1658,1194],{"class":107},[97,1660,1661],{"class":99,"line":406},[97,1662,1663],{"class":107},"      {\n",[97,1665,1666,1669,1672],{"class":99,"line":411},[97,1667,1668],{"class":107},"        name: ",[97,1670,1671],{"class":114},"'watcher'",[97,1673,150],{"class":107},[97,1675,1676,1679,1681,1685],{"class":99,"line":1204},[97,1677,1678],{"class":134},"        configureServer",[97,1680,1095],{"class":107},[97,1682,1684],{"class":1683},"sP4rz","server",[97,1686,1687],{"class":107},") {\n",[97,1689,1690,1693,1696],{"class":99,"line":1210},[97,1691,1692],{"class":107},"          server.watcher.",[97,1694,1695],{"class":134},"add",[97,1697,1698],{"class":107},"([componentsDir, pagesDir])\n",[97,1700,1701],{"class":99,"line":1216},[97,1702,1703],{"class":107},"        },\n",[97,1705,1706],{"class":99,"line":1222},[97,1707,1708],{"class":107},"      },\n",[97,1710,1711],{"class":99,"line":1228},[97,1712,1713],{"class":161},"      \u002F\u002F ...\n",[97,1715,1716],{"class":99,"line":1281},[97,1717,1320],{"class":107},[97,1719,1720],{"class":99,"line":1293},[97,1721,934],{"class":107},[97,1723,1724],{"class":99,"line":1299},[97,1725,168],{"class":107},[10,1727,1728],{},"With this adjustment, everything should function as intended. The plugin generates the declaration file, providing auto-completion and type checking within our IDE when a component is created without the needs to restart the development server.",[23,1730,1732],{"id":1731},"on-demand-everything","On-demand everything",[10,1734,1735],{},"Can this on-demand philosophy extend further to include everything?",[10,1737,1738,1739,1742,1743,1746,1747,1750],{},"Absolutely, and we will achieve this using the ",[28,1740,1741],{},"unplugin-auto-import"," plugin. This plugin functions similarly to the ",[28,1744,1745],{},"unplugin-vue-components"," plugin but for ",[14,1748,1749],{},"JavaScript and TypeScript"," files.",[10,1752,1753],{},"First, we must install the plugin:",[88,1755,1757],{"className":815,"code":1756,"filename":817,"language":818,"meta":93,"style":93},"pnpm add -D unplugin-auto-import\n",[28,1758,1759],{"__ignoreMap":93},[97,1760,1761,1763,1765,1767],{"class":99,"line":100},[97,1762,825],{"class":134},[97,1764,828],{"class":114},[97,1766,831],{"class":635},[97,1768,1769],{"class":114}," unplugin-auto-import\n",[10,1771,1772,1773,86],{},"Next, configure the plugin in the ",[28,1774,79],{},[88,1776,1778],{"className":90,"code":1777,"filename":79,"language":92,"meta":93,"style":93},"import { dirname, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport AutoImport from 'unplugin-auto-import\u002Fvite'\nimport { defineConfig } from 'vitepress'\n\nconst currentDir = dirname(fileURLToPath(import.meta.url))\n\n\u002F\u002F ...\n\nconst composablesDir = resolve(currentDir, 'theme', 'composables')\nconst utilsDir = resolve(currentDir, 'theme', 'utils')\n\nexport default defineConfig({\n  srcDir: 'src',\n\n  vite: {\n    plugins: [\n      {\n        name: 'watcher',\n        configureServer(server) {\n          \u002F\u002F ...\n          server.watcher.add([composablesDir, utilsDir])\n        },\n      },\n      AutoImport({\n        imports: ['vue', 'vitepress'],\n        dirs: [composablesDir, utilsDir],\n        dts: resolve(currentDir, 'auto-imports.d.ts'),\n      }),\n      \u002F\u002F ...\n    ],\n  },\n})\n",[28,1779,1780,1790,1800,1812,1822,1826,1850,1854,1859,1863,1885,1907,1911,1921,1929,1933,1937,1941,1945,1953,1963,1968,1977,1981,1985,1992,2007,2012,2026,2030,2035,2040,2045],{"__ignoreMap":93},[97,1781,1782,1784,1786,1788],{"class":99,"line":100},[97,1783,104],{"class":103},[97,1785,1036],{"class":107},[97,1787,111],{"class":103},[97,1789,1041],{"class":114},[97,1791,1792,1794,1796,1798],{"class":99,"line":118},[97,1793,104],{"class":103},[97,1795,1048],{"class":107},[97,1797,111],{"class":103},[97,1799,1053],{"class":114},[97,1801,1802,1804,1807,1809],{"class":99,"line":125},[97,1803,104],{"class":103},[97,1805,1806],{"class":107}," AutoImport ",[97,1808,111],{"class":103},[97,1810,1811],{"class":114}," 'unplugin-auto-import\u002Fvite'\n",[97,1813,1814,1816,1818,1820],{"class":99,"line":141},[97,1815,104],{"class":103},[97,1817,108],{"class":107},[97,1819,111],{"class":103},[97,1821,115],{"class":114},[97,1823,1824],{"class":99,"line":153},[97,1825,122],{"emptyLinePlaceholder":121},[97,1827,1828,1830,1832,1834,1836,1838,1840,1842,1844,1846,1848],{"class":99,"line":158},[97,1829,629],{"class":103},[97,1831,1086],{"class":635},[97,1833,1089],{"class":103},[97,1835,1092],{"class":134},[97,1837,1095],{"class":107},[97,1839,1098],{"class":134},[97,1841,1095],{"class":107},[97,1843,104],{"class":103},[97,1845,737],{"class":107},[97,1847,1107],{"class":635},[97,1849,1110],{"class":107},[97,1851,1852],{"class":99,"line":165},[97,1853,122],{"emptyLinePlaceholder":121},[97,1855,1856],{"class":99,"line":367},[97,1857,1858],{"class":161},"\u002F\u002F ...\n",[97,1860,1861],{"class":99,"line":373},[97,1862,122],{"emptyLinePlaceholder":121},[97,1864,1865,1867,1870,1872,1874,1876,1878,1880,1883],{"class":99,"line":379},[97,1866,629],{"class":103},[97,1868,1869],{"class":635}," composablesDir",[97,1871,1089],{"class":103},[97,1873,1126],{"class":134},[97,1875,1129],{"class":107},[97,1877,1132],{"class":114},[97,1879,486],{"class":107},[97,1881,1882],{"class":114},"'composables'",[97,1884,1140],{"class":107},[97,1886,1887,1889,1892,1894,1896,1898,1900,1902,1905],{"class":99,"line":385},[97,1888,629],{"class":103},[97,1890,1891],{"class":635}," utilsDir",[97,1893,1089],{"class":103},[97,1895,1126],{"class":134},[97,1897,1129],{"class":107},[97,1899,1132],{"class":114},[97,1901,486],{"class":107},[97,1903,1904],{"class":114},"'utils'",[97,1906,1140],{"class":107},[97,1908,1909],{"class":99,"line":391},[97,1910,122],{"emptyLinePlaceholder":121},[97,1912,1913,1915,1917,1919],{"class":99,"line":396},[97,1914,128],{"class":103},[97,1916,131],{"class":103},[97,1918,135],{"class":134},[97,1920,138],{"class":107},[97,1922,1923,1925,1927],{"class":99,"line":401},[97,1924,144],{"class":107},[97,1926,147],{"class":114},[97,1928,150],{"class":107},[97,1930,1931],{"class":99,"line":406},[97,1932,122],{"emptyLinePlaceholder":121},[97,1934,1935],{"class":99,"line":411},[97,1936,1189],{"class":107},[97,1938,1939],{"class":99,"line":1204},[97,1940,1194],{"class":107},[97,1942,1943],{"class":99,"line":1210},[97,1944,1663],{"class":107},[97,1946,1947,1949,1951],{"class":99,"line":1216},[97,1948,1668],{"class":107},[97,1950,1671],{"class":114},[97,1952,150],{"class":107},[97,1954,1955,1957,1959,1961],{"class":99,"line":1222},[97,1956,1678],{"class":134},[97,1958,1095],{"class":107},[97,1960,1684],{"class":1683},[97,1962,1687],{"class":107},[97,1964,1965],{"class":99,"line":1228},[97,1966,1967],{"class":161},"          \u002F\u002F ...\n",[97,1969,1970,1972,1974],{"class":99,"line":1281},[97,1971,1692],{"class":107},[97,1973,1695],{"class":134},[97,1975,1976],{"class":107},"([composablesDir, utilsDir])\n",[97,1978,1979],{"class":99,"line":1293},[97,1980,1703],{"class":107},[97,1982,1983],{"class":99,"line":1299},[97,1984,1708],{"class":107},[97,1986,1987,1990],{"class":99,"line":1305},[97,1988,1989],{"class":134},"      AutoImport",[97,1991,138],{"class":107},[97,1993,1994,1997,2000,2002,2005],{"class":99,"line":1311},[97,1995,1996],{"class":107},"        imports: [",[97,1998,1999],{"class":114},"'vue'",[97,2001,486],{"class":107},[97,2003,2004],{"class":114},"'vitepress'",[97,2006,1278],{"class":107},[97,2008,2009],{"class":99,"line":1317},[97,2010,2011],{"class":107},"        dirs: [composablesDir, utilsDir],\n",[97,2013,2014,2016,2018,2020,2023],{"class":99,"line":1323},[97,2015,1284],{"class":107},[97,2017,1287],{"class":134},[97,2019,1129],{"class":107},[97,2021,2022],{"class":114},"'auto-imports.d.ts'",[97,2024,2025],{"class":107},"),\n",[97,2027,2028],{"class":99,"line":1328},[97,2029,1314],{"class":107},[97,2031,2033],{"class":99,"line":2032},30,[97,2034,1713],{"class":161},[97,2036,2038],{"class":99,"line":2037},31,[97,2039,1320],{"class":107},[97,2041,2043],{"class":99,"line":2042},32,[97,2044,934],{"class":107},[97,2046,2048],{"class":99,"line":2047},33,[97,2049,168],{"class":107},[10,2051,2052],{},"With this configuration, we accomplish three objectives:",[993,2054,2055,2078,2088],{},[287,2056,2057,2058,2061,2062,471,2064,2067,2068,486,2071,486,2074,2077],{},"Automatically import all ",[14,2059,2060],{},"composable and utility functions"," from ",[28,2063,584],{},[28,2065,2066],{},"vitepress",", allowing ",[28,2069,2070],{},"ref",[28,2072,2073],{},"computed",[28,2075,2076],{},"useData",", etc., to be used without explicit imports.",[287,2079,2080,2081,471,2084,2087],{},"Scan and register all composable and utility functions in the ",[28,2082,2083],{},"theme\u002Fcomposables",[28,2085,2086],{},"theme\u002Futils"," directories.",[287,2089,2090,2091,471,2093,2095,2096,2098],{},"Enable the watcher to monitor ",[28,2092,2083],{},[28,2094,2086],{}," directories, similar to the ",[28,2097,1745],{}," plugin.",[10,2100,2101,2102,2105,2106,2108,2109,530],{},"This plugin generates an ",[28,2103,2104],{},"auto-imports.d.ts"," file for the same reasons as the ",[28,2107,1378],{}," file. It too should be added to the ",[28,2110,1474],{},[88,2112,2114],{"className":208,"code":2113,"filename":1378,"language":211,"meta":93,"style":93},"node_modules\ncache\ncomponents.d.ts\nauto-imports.d.ts\n",[28,2115,2116,2120,2124,2128],{"__ignoreMap":93},[97,2117,2118],{"class":99,"line":100},[97,2119,1484],{},[97,2121,2122],{"class":99,"line":118},[97,2123,1489],{},[97,2125,2126],{"class":99,"line":125},[97,2127,1494],{},[97,2129,2130],{"class":99,"line":141},[97,2131,2132],{},"auto-imports.d.ts\n",[23,2134,2136],{"id":2135},"scripts","Scripts",[10,2138,2139,2140,2143,2144,2146],{},"To conclude this article, let's remove the ",[28,2141,2142],{},"docs:"," prefix from our scripts in the ",[28,2145,975],{}," file. Since we're not creating documentation, and VitePress is the sole project in the repository, we can safely eliminate this prefix.",[88,2148,2150],{"className":867,"code":2149,"filename":975,"language":869,"meta":93,"style":93},"{\n  \"scripts\": {\n    \"dev\": \"vitepress dev\",\n    \"build\": \"vitepress build\",\n    \"preview\": \"vitepress preview\"\n  }\n}\n",[28,2151,2152,2156,2163,2175,2187,2197,2201],{"__ignoreMap":93},[97,2153,2154],{"class":99,"line":100},[97,2155,876],{"class":107},[97,2157,2158,2161],{"class":99,"line":118},[97,2159,2160],{"class":635},"  \"scripts\"",[97,2162,884],{"class":107},[97,2164,2165,2168,2170,2173],{"class":99,"line":125},[97,2166,2167],{"class":635},"    \"dev\"",[97,2169,553],{"class":107},[97,2171,2172],{"class":114},"\"vitepress dev\"",[97,2174,150],{"class":107},[97,2176,2177,2180,2182,2185],{"class":99,"line":141},[97,2178,2179],{"class":635},"    \"build\"",[97,2181,553],{"class":107},[97,2183,2184],{"class":114},"\"vitepress build\"",[97,2186,150],{"class":107},[97,2188,2189,2192,2194],{"class":99,"line":153},[97,2190,2191],{"class":635},"    \"preview\"",[97,2193,553],{"class":107},[97,2195,2196],{"class":114},"\"vitepress preview\"\n",[97,2198,2199],{"class":99,"line":158},[97,2200,1464],{"class":107},[97,2202,2203],{"class":99,"line":165},[97,2204,953],{"class":107},[10,2206,2207,2208,2211,2212,2215,2216,2218,2219,737],{},"Excellent! We now have a clean and organized ",[14,2209,2210],{},"project structure",", ready to commence our ",[14,2213,2214],{},"blogging endeavor",". In the subsequent article, we will develop the ",[14,2217,749],{}," and leverage one of VitePress's core features: the ",[14,2220,2221],{},"data loader",[2223,2224,2225],"style",{},"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 .sIIMD, html code.shiki .sIIMD{--shiki-light:#032F62;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .snPdu, html code.shiki .snPdu{--shiki-light:#6F42C1;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sovSZ, html code.shiki .sovSZ{--shiki-light:#22863A;--shiki-default:#22863A;--shiki-dark:#85E89D}html pre.shiki code .syb_3, html code.shiki .syb_3{--shiki-light:#005CC5;--shiki-light-font-weight:bold;--shiki-default:#005CC5;--shiki-default-font-weight:bold;--shiki-dark:#79B8FF;--shiki-dark-font-weight:bold}html pre.shiki code .sBjJW, html code.shiki .sBjJW{--shiki-light:#005CC5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sujWL, html code.shiki .sujWL{--shiki-light:#22863A;--shiki-light-font-weight:bold;--shiki-default:#22863A;--shiki-default-font-weight:bold;--shiki-dark:#85E89D;--shiki-dark-font-weight:bold}html pre.shiki code .s3JiQ, html code.shiki .s3JiQ{--shiki-light:#032F62;--shiki-default:#032F62;--shiki-dark:#DBEDFF}html pre.shiki code .sP4rz, html code.shiki .sP4rz{--shiki-light:#E36209;--shiki-default:#E36209;--shiki-dark:#FFAB70}",{"title":93,"searchDepth":118,"depth":118,"links":2227},[2228,2230,2232,2234,2238,2239],{"id":25,"depth":118,"text":2229},"The src directory",{"id":263,"depth":118,"text":2231},"The .vitepress directory",{"id":430,"depth":118,"text":2233},"The pages directory",{"id":752,"depth":118,"text":753,"children":2235},[2236,2237],{"id":795,"depth":125,"text":796},{"id":58,"depth":125,"text":988},{"id":1731,"depth":118,"text":1732},{"id":2135,"depth":118,"text":2136},"900d11a5-ff68-4cc9-8ace-66a5cb1577fa","2024-10-18","Discover how to optimize your VitePress blog's architecture design with scalable solutions and efficient Vite plugin integration.",{"branch":2244},"03.define-the-design-of-the-blog-architecture",null,{},"\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Foptimize-your-vitepress-blog-architecture-design","---\ncontentId: 900d11a5-ff68-4cc9-8ace-66a5cb1577fa\npart: 3\ntitle: Optimize Your VitePress Blog's Architecture Design\ndescription: Discover how to optimize your VitePress blog's architecture design with scalable solutions and efficient Vite plugin integration.\ngithub:\n  branch: 03.define-the-design-of-the-blog-architecture\ndate: 2024-10-18\nseriesSlug: create-a-blog-with-vitepress-and-vue-js-from-scratch\n---\n\nIn the preceding article, we initialized our **VitePress project** and examined its structure. We also began incorporating our custom theme. Today, we will further progress by defining the **blog's architecture** and design to ensure it remains manageable and scalable over time.\n\n## The `src` directory\n\nTo begin, we will relocate our project's **source files** to a designated `src` directory. This approach prevents cluttering the root directory with **source files** and avoids including unwanted files like `README.md` in our project's pages.\n\nWhat constitutes our source files? Specifically, is the theme a source file? The answer is no. As we're developing a **content-centric website**, only markdown and public files are considered source files. Everything related to the theme is part of the VitePress **configuration** and will reside in the `.vitepress` directory.\n\nTo modify the source directory, we need to update the [`srcDir`](https:\u002F\u002Fvitepress.dev\u002Freference\u002Fsite-config#srcdir) option in the `config.mts` file located in the `.vitepress` directory. Here is the revised content of the `config.mts` file:\n\n```ts [config.mts]\nimport { defineConfig } from 'vitepress'\n\nexport default defineConfig({\n  srcDir: 'src',\n\n  \u002F\u002F ...\n})\n```\n\nThis option informs **VitePress** where our **markdown pages** are stored relative to the project root. In our instance, the project root is the repository's root.\n\nThe `src` directory will also encompass a `public` directory, where **static assets** like images, fonts, and other unaltered files will be stored.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nThe `public` directory associates with the site's root and is not processed by VitePress. Therefore, files in the `public` directory will be copied to the root of the generated site without any transformation.\n::\n\n```txt [Example]\n.\n├── .vitepress\n│   └── config.mts\n├── src\n│   ├── public\n│   └── index.md\n└── package.json\n```\n\nThis structure is significantly cleaner and more organized. If we aim to write a **blog post**, we simply open the `src` directory, and if we desire to update our theme, we access the `.vitepress` directory.\n\n## The `.vitepress` directory\n\nRegarding the `.vitepress` directory, we can create subdirectories to aid in structuring our **theme**, maintaining simplicity akin to a standard Vite + Vue project.\n\nUnder `.vitepress\u002Ftheme`, we will establish the following directories:\n\n- `components`: Contains all the Vue components used in the theme.\n- `composables`: Contains all the Vue composables utilized in the theme.\n- `pages`: Contains all the Vue components employed as pages in the `Layout.vue` component.\n- `styles`: Contains all the CSS files applied in the theme.\n- `types`: Contains all the TypeScript types utilized in the theme.\n- `utils`: Contains all the utility functions used in the theme.\n\n```txt [Layout.vue]\n.\n├── .vitepress\n│   ├── theme\n│   │   ├── components\n│   │   ├── composables\n│   │   ├── pages\n│   │   ├── styles\n│   │   ├── types\n│   │   ├── utils\n│   │   ├── index.ts\n│   │   └── Layout.vue\n│   └── config.mts\n├── src\n│   ├── public\n│   └── index.md\n└── package.json\n```\n\nThis structure closely mirrors what many **Vue developers** are accustomed to, which is advantageous! It eliminates the need to learn a new project structure while utilizing VitePress. If you're familiar with structuring a **Vue project**, you already know how to structure a **VitePress project**. 👌\n\n## The `pages` directory\n\nI acknowledge this might seem confusing. I mentioned earlier that VitePress features a minimal router, and routes are generated from the `src` directory's structure. So, what do these `pages` imply?\n\nVitePress follows the convention of using `Layout.vue` as the entry point for the Vue application. Given this scenario, having a `layouts` directory would imply that a layout utilizes a layout, which seems peculiar to me.\n\nRenaming `Layout.vue` to `App.vue` might be an option, yet I find it less appealing. I prefer retaining the `Layout.vue` name as it's a VitePress convention. Moreover, as VitePress doesn't have a router, we can't use a ` RouterView` component to render the layout and the page. This implies that `Layout.vue` and `App.vue` serve different purposes.\n\nUltimately, establishing a **`pages` directory** seemed the most logical decision. Within this directory, we include Vue components such as `NotFound.vue`, `Blog\u002FBlogIndex.vue`, `Blog\u002FBlogPost.vue`, etc., forming a file routing system.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nThe `pages` directory is my approach to organizing the project. It's not mandated by VitePress. Any `.vue` files could reside in the `components` or `layouts` directory. Feel free to customize the structure according to your preferences.\n::\n\nIn conclusion, we'll use `Layout.vue` to route our Markdown files to the appropriate **page component**. To accomplish this, we'll use the `layout` key in the frontmatter of our Markdown files. This key facilitates importing the correct **page component** in the `Layout.vue` file.\n\nConsider the following Markdown file:\n\n```md [Layout.vue]\n---\nlayout: blog-post\n---\n\n# Hello, World!\n```\n\nIn the `Layout.vue` file, we can render the `Blog\u002FBlogPost.vue` component as follows:\n\n```vue [Blog\u002FBlogPost.vue]\n\u003Cscript lang=\"ts\" setup>\nimport { useData } from 'vitepress'\n\nconst { frontmatter } = useData() \u002F\u002F This is the frontmatter of the current Markdown file\n\u003C\u002Fscript>\n\n\u003Ctemplate>\n  \u003CBlogPost v-if=\"frontmatter.layout === 'blog-post'\" \u002F>\n\n  \u003CContent v-else \u002F> \u002F\u002F Just render the content of the Markdown file\n\u003C\u002Ftemplate>\n```\n\nThis approach enables a dynamic routing system without an actual router. Meanwhile, **`Layout.vue`** remains the entry point of the **Vue application**.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\n If anything isn't clear, don't worry. We'll apply this in the upcoming articles when introducing **blog posts** and the **blog list**.\n::\n\n## Configuring Unplugin Vue Components\n\nIn the previous code snippet, we used the `BlogPost` component without importing it. This magic becomes feasible with the help of [Unplugin Vue Components](https:\u002F\u002Fgithub.com\u002Funplugin\u002Funplugin-vue-components).\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nThis step is entirely optional, and you can skip it if desired. For me, it's an excellent way to maintain clean code, and as a **Nuxt user**, I have a slight preference for this method. 😅\n::\n\nBehind the scenes, this plugin for Vite scans our files for Vue components as they pass through the Vite pipeline. When it detects a component, it adds the relevant **import statement** at the top of the file. This aligns with Vite's **on-demand** philosophy, ensuring small bundle sizes and allowing component chunking where they are utilized.\n\nThis plugin seamlessly integrates with TypeScript, ensuring that we do not compromise type checking or **auto-completion** in our IDE.\n\n### Installing necessary dependencies\n\nFirst, we must install **TypeScript** and the **Node types**. This is essential as the plugin generates a [declaration file](https:\u002F\u002Fwww.typescriptlang.org\u002Fdocs\u002Fhandbook\u002F2\u002Ftype-declarations.html#dts-files) containing our components' types.\n\n```bash [terminal]\npnpm add -D typescript @types\u002Fnode vue\n```\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nThe installation of `vue` is required when utilizing pnpm due to its hoisting mechanism. Refer to the [`shamefully-hoist` option](https:\u002F\u002Fpnpm.io\u002Fnpmrc#shamefully-hoist) for further explanation.\n::\n\nNext, a `tsconfig.json` file should be created at the project's root to guide TypeScript's behavior.\n\n```json [tsconfig.json]\n{\n  \"compilerOptions\": {\n    \"target\": \"ESNext\",\n    \"module\": \"ESNext\",\n    \"moduleResolution\": \"Bundler\",\n    \"strict\": true\n  },\n  \"include\": [\".\u002F.vitepress\u002F**\u002F*\"]\n}\n```\n\nThe `@types\u002Fnode` is automatically incorporated by TypeScript. We include all files within the `.vitepress` directory where our TypeScript and Vue components reside. This pattern also imports `.d.ts` files, which is crucial for the plugin.\n\nYou should also add `\"type\": \"module\"` in the `package.json` file and modify the extensions of `postcss.config.js` and `tailwind.config.js` to `.cjs`.\n\n### Configuration\n\nFinalizing the configuration of the plugin is straightforward:\n\n1. Indicate to the plugin the directory where our **Vue components** reside.\n2. Define to the plugin the naming conventions for our **Vue components**.\n3. Specify to the plugin the location for creating the **declaration file**.\n\nGiven the `config.mts` file resides within the `.vitepress` directory, there is more configuration than in a standard Vite project where the configuration `vite.config.ts` is situated at the project's root.\n\n```ts [vite.config.ts]\nimport { dirname, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport Components from 'unplugin-vue-components\u002Fvite'\nimport { defineConfig } from 'vitepress'\n\nconst currentDir = dirname(fileURLToPath(import.meta.url))\n\nconst componentsDir = resolve(currentDir, 'theme', 'components')\nconst pagesDir = resolve(currentDir, 'theme', 'pages')\n\nexport default defineConfig({\n  \u002F\u002F ...\n\n  vite: {\n    plugins: [\n      Components({\n        dirs: [\n          componentsDir,\n          pagesDir,\n        ],\n        include: [\u002F\\.vue$\u002F, \u002F\\.vue\\?vue\u002F, \u002F\\.md$\u002F],\n        dts: resolve(\n          currentDir,\n          'components.d.ts'\n        ),\n      }),\n    ],\n  },\n})\n```\n\nThe `dirs` option directs the plugin to where our components are located. In our context, we have two directories: `theme\u002Fpages` and `theme\u002Fcomponents`, relative to the `config.mts` file. This distinction matters because the process initiates in the project's root, but the configuration lies within the `.vitepress` directory. It prevents the use of `..\u002F..\u002F` in paths.\n\nThe `include` option specifies the file extensions that should be scanned to add import statements. We include `.vue` and `.md` files as we might have Vue components in **Markdown files** without the need for explicit imports, which is a fantastic feature.\n\nThe `dts` option guides the plugin on where to create the declaration file. We desire to create the `components.d.ts` file within the `.vitepress` directory's root. This declaration file aids our IDE and TypeScript in providing auto-completion and type checking, even when components are not explicitly imported.\n\nWhen we launch our development server, we should verify the plugin's functionality by examining the `components.d.ts` file. Initially, this file might not feature any components as we don't have any. Creating a temporary component will allow observation of the changes and requires a development server restart. Use \u003Ckbd>r\u003C\u002Fkbd> to restart the server.\n\n::callout{icon=\"i-ph-info-duotone\" color=\"info\"}\nThe current setup will not function as described, and it's normal. **Continue reading to understand why and see the final configuration.**\n::\n\n```ts [components.d.ts]\n\u002F\u002F Generated by unplugin-vue-components\n\u002F\u002F Read more: https:\u002F\u002Fgithub.com\u002Fvuejs\u002Fcore\u002Fpull\u002F3399\nexport {}\n\n\u002F* prettier-ignore *\u002F\ndeclare module 'vue' {\n  export interface GlobalComponents {\n  }\n}\n```\n\nThis file is generated by the plugin, should remain unchanged manually, and should be added to the `.gitignore` file.\n\n```txt [Example]\nnode_modules\ncache\ncomponents.d.ts\n```\n\nHowever, the present setup does not work due to limitations originating from Vite. Underneath, the plugin connects to the Vite files watcher, meaning it only responds to files and directories monitored by Vite. Vite, by default, watches only the `root` directory specified by the `srcDir` of the `config.mts` file. Consequently, files and directories within the `.vitepress` directory remain undetected by Vite and the plugin.\n\nTo address this, we must instruct Vite to monitor the directory where our **Vue components and pages** reside. This is achieved by devising a compact plugin to update Vite's watcher configuration:\n\n```ts [config.mts]\nimport { dirname, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { defineConfig } from 'vitepress'\n\nconst currentDir = dirname(fileURLToPath(import.meta.url))\n\nconst componentsDir = resolve(currentDir, 'theme', 'components')\nconst pagesDir = resolve(currentDir, 'theme', 'pages')\n\nexport default defineConfig({\n  srcDir: 'src',\n\n  vite: {\n    plugins: [\n      {\n        name: 'watcher',\n        configureServer(server) {\n          server.watcher.add([componentsDir, pagesDir])\n        },\n      },\n      \u002F\u002F ...\n    ],\n  },\n})\n```\n\nWith this adjustment, everything should function as intended. The plugin generates the declaration file, providing auto-completion and type checking within our IDE when a component is created without the needs to restart the development server.\n\n## On-demand everything\n\nCan this on-demand philosophy extend further to include everything?\n\nAbsolutely, and we will achieve this using the `unplugin-auto-import` plugin. This plugin functions similarly to the `unplugin-vue-components` plugin but for **JavaScript and TypeScript** files.\n\nFirst, we must install the plugin:\n\n```bash [terminal]\npnpm add -D unplugin-auto-import\n```\n\nNext, configure the plugin in the `config.mts` file:\n\n```ts [config.mts]\nimport { dirname, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport AutoImport from 'unplugin-auto-import\u002Fvite'\nimport { defineConfig } from 'vitepress'\n\nconst currentDir = dirname(fileURLToPath(import.meta.url))\n\n\u002F\u002F ...\n\nconst composablesDir = resolve(currentDir, 'theme', 'composables')\nconst utilsDir = resolve(currentDir, 'theme', 'utils')\n\nexport default defineConfig({\n  srcDir: 'src',\n\n  vite: {\n    plugins: [\n      {\n        name: 'watcher',\n        configureServer(server) {\n          \u002F\u002F ...\n          server.watcher.add([composablesDir, utilsDir])\n        },\n      },\n      AutoImport({\n        imports: ['vue', 'vitepress'],\n        dirs: [composablesDir, utilsDir],\n        dts: resolve(currentDir, 'auto-imports.d.ts'),\n      }),\n      \u002F\u002F ...\n    ],\n  },\n})\n```\n\nWith this configuration, we accomplish three objectives:\n\n1. Automatically import all **composable and utility functions** from `vue` and `vitepress`, allowing `ref`, `computed`, `useData`, etc., to be used without explicit imports.\n2. Scan and register all composable and utility functions in the `theme\u002Fcomposables` and `theme\u002Futils` directories.\n3. Enable the watcher to monitor `theme\u002Fcomposables` and `theme\u002Futils` directories, similar to the `unplugin-vue-components` plugin.\n\nThis plugin generates an `auto-imports.d.ts` file for the same reasons as the `components.d.ts` file. It too should be added to the `.gitignore` file.\n\n```txt [components.d.ts]\nnode_modules\ncache\ncomponents.d.ts\nauto-imports.d.ts\n```\n\n## Scripts\n\nTo conclude this article, let's remove the `docs:` prefix from our scripts in the `package.json` file. Since we're not creating documentation, and VitePress is the sole project in the repository, we can safely eliminate this prefix.\n\n```json [package.json]\n{\n  \"scripts\": {\n    \"dev\": \"vitepress dev\",\n    \"build\": \"vitepress build\",\n    \"preview\": \"vitepress preview\"\n  }\n}\n```\n\nExcellent! We now have a clean and organized **project structure**, ready to commence our **blogging endeavor**. In the subsequent article, we will develop the **blog list** and leverage one of VitePress's core features: the **data loader**.\n",{"title":5,"description":2242},"create-a-blog-with-vitepress-and-vue-js-from-scratch",{"loc":2247},"series\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Foptimize-your-vitepress-blog-architecture-design","5uwBdg6HhyuNwlbuDKPCxR9mZP0o2x2YPkJyjugWwSg",{"overview":2255,"chapters":2489},{"id":2256,"title":2257,"body":2258,"contentId":2470,"date":2471,"description":2472,"extension":538,"github":2473,"meetTheInstructor":2476,"meta":2477,"navigation":121,"part":2245,"path":2478,"rawbody":2479,"robots":2245,"schemaOrg":2245,"seo":2480,"seriesSlug":2250,"sitemap":2481,"stem":2484,"subtitle":2485,"topics":2486,"__hash__":2488},"series\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch.md","Create a Blog with VitePress and Vue.js from Scratch",{"type":7,"value":2259,"toc":2467},[2260,2263,2276,2290,2422,2433,2444,2451,2454,2457,2461],[10,2261,2262],{},"Hello and welcome! 👋",[10,2264,2265,2266,2269,2270,471,2272,2275],{},"You're about to embark on the \"Create a ",[14,2267,2268],{},"Blog"," with ",[14,2271,174],{},[14,2273,2274],{},"Vue.js"," from Scratch\" series!",[10,2277,2278,2279,2285,2286,2289],{},"Throughout this journey, we will construct a practical blog from the ground up using ",[68,2280,2283],{"href":2281,"rel":2282},"https:\u002F\u002Fvitepress.dev\u002F",[72],[14,2284,174],{},". We will explore a range of topics from initial configuration to deploying on ",[14,2287,2288],{},"Cloudflare Pages",", including:",[284,2291,2292,2314,2324,2329,2342,2348,2358,2368,2378,2390,2407,2413],{},[287,2293,2294,2297,2298,2300,2301,471,2308,2313],{},[14,2295,2296],{},"Getting Started with VitePress: Project Setup and Essentials",": Learn to set up a fresh ",[14,2299,16],{}," by incorporating ",[68,2302,2305],{"href":2303,"rel":2304},"https:\u002F\u002Ftailwindcss.com\u002F",[72],[14,2306,2307],{},"Tailwind CSS",[68,2309,2311],{"href":762,"rel":2310},[72],[14,2312,1745],{}," for an enhanced development process.",[287,2315,2316,2319,2320],{},[14,2317,2318],{},"From Default to Custom: Building a VitePress Blog Theme",": We will entirely remove the default theme and create a personalized theme. ",[2321,2322,2323],"em",{},"You'll be surprised by its simplicity!",[287,2325,2326,2328],{},[14,2327,5],{},": Discover how to organize code and design your blog for scalability and maintainability.",[287,2330,2331,2334,2335,737],{},[14,2332,2333],{},"Implementing Blog Index with VitePress and Tailwind CSS",": Create a list of blog posts. This will introduce ",[68,2336,2339],{"href":2337,"rel":2338},"https:\u002F\u002Fvitepress.dev\u002Fguide\u002Fdata-loading",[72],[14,2340,2341],{},"data loaders from VitePress",[287,2343,2344,2347],{},[14,2345,2346],{},"Single Blog Rendering in VitePress with Tailwind Typography",": Create a page dedicated to reading each blog post.",[287,2349,2350,2353,2354,2357],{},[14,2351,2352],{},"Deploy VitePress Blog Globally with Cloudflare Pages",": Integrate ",[14,2355,2356],{},"SEO metadata"," for improved search engine visibility, eliminating the need for manual updates.",[287,2359,2360,2363,2364,2367],{},[14,2361,2362],{},"Showcase Your GitHub Projects on Your VitePress Blog",": Develop a page to display your ",[14,2365,2366],{},"GitHub"," endeavors, extending the use of data loaders and demonstrating their flexibility.",[287,2369,2370,2373,2374,2377],{},[14,2371,2372],{},"Creating Open Graph Images Automatically for Each Blog Post",": Efficiently create ",[14,2375,2376],{},"Open Graph images"," for each post, saving time and enhancing appeal.",[287,2379,2380,2382,2383,2389],{},[14,2381,2352],{},": Seamlessly deploy your blog to ",[68,2384,2387],{"href":2385,"rel":2386},"https:\u002F\u002Fpages.cloudflare.com\u002F",[72],[14,2388,2288],{},", achieving this in just a few clicks!",[287,2391,2392,2395,2396,2269,2399,2406],{},[14,2393,2394],{},"Ensure Blog Quality with Playwright Automated Testing",": Implement ",[14,2397,2398],{},"end-to-end testing",[68,2400,2403],{"href":2401,"rel":2402},"https:\u002F\u002Fplaywright.dev\u002F",[72],[14,2404,2405],{},"Playwright"," to ensure your blog functions as expected.",[287,2408,2409,2412],{},[14,2410,2411],{},"An Internal Refactor for the Future Growth of our Blog",": Prepare your blog for future growth by refactoring the codebase, ensuring it remains maintainable and scalable.",[287,2414,2415,2418,2419,2421],{},[14,2416,2417],{},"Migrating Our VitePress Blog to Tailwind CSS Version 4",": Upgrade our blog to the latest version of ",[14,2420,2307],{}," to leverage its new features and improvements.",[10,2423,2424,2425,2428,2429,2432],{},"By the conclusion, you will possess a fully operational and captivating ",[14,2426,2427],{},"blog",", allowing you to concentrate exclusively on producing ",[14,2430,2431],{},"content",", which is paramount. Simply write and publish, as the blog will autonomously manage the rest.",[2434,2435,2436,2441],"figure",{},[2437,2438],"img",{"alt":2439,"src":2440},"Home Page of our Blog","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fdeploy-vitepress-blog-globally-with-cloudflare-pages\u002Fvitepress-home.png",[2442,2443,2439],"figcaption",{},[10,2445,2446,2447,2450],{},"This series offers a detailed, step-by-step ",[14,2448,2449],{},"guide",". Rest assured, each aspect will be thoroughly elucidated, from selecting to implementing every feature. While each feature will be minimal and focused on the core, this does not mean we will forgo creating a visually pleasing and functional blog.",[10,2452,2453],{},"Should you have any inquiries, please feel free to engage in the comments section under each article.",[10,2455,2456],{},"I hope you find this series truly enjoyable! 🚀",[23,2458,2460],{"id":2459},"chapters","Chapters",[2462,2463],"series-chapters-list",{"className":2464},[2465,2466],"mx-auto","max-w-5xl",{"title":93,"searchDepth":118,"depth":118,"links":2468},[2469],{"id":2459,"depth":118,"text":2460},"43c95b33-041c-4108-ab98-0d21ef60ed7f","2024-10-10","Build a dynamic blog with VitePress and Vue.js from scratch. Learn setup, SEO, and deployment for a seamless blogging experience.",{"name":2474,"repository":2475},"garabit","barbapapazes\u002Fgarabit","I create this series because \u003Cstrong>VitePress\u003C\u002Fstrong> is way more powerful than it seems at the first glance. I was amazed by the \u003Cstrong>flexibility\u003C\u002Fstrong> and the \u003Cstrong>simplicity\u003C\u002Fstrong> of the tool while building my blog and wanted the community to know about it.",{},"\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch","---\ncontentId: 43c95b33-041c-4108-ab98-0d21ef60ed7f\ntitle: Create a Blog with VitePress and Vue.js from Scratch\nsubtitle: A new perspective on blogging with VitePress and Vue.js\ndescription: Build a dynamic blog with VitePress and Vue.js from scratch. Learn setup, SEO, and deployment for a seamless blogging experience.\ndate: 2024-10-10\ntopics:\n  - vuejs\n  - vitepress\n  - blog\ngithub:\n  name: garabit\n  repository: barbapapazes\u002Fgarabit\nmeetTheInstructor: I create this series because \u003Cstrong>VitePress\u003C\u002Fstrong> is way more powerful than it seems at the first glance. I was amazed by the \u003Cstrong>flexibility\u003C\u002Fstrong> and the \u003Cstrong>simplicity\u003C\u002Fstrong> of the tool while building my blog and wanted the community to know about it.\nseriesSlug: create-a-blog-with-vitepress-and-vue-js-from-scratch\n---\n\nHello and welcome! 👋\n\nYou're about to embark on the \"Create a **Blog** with **VitePress** and **Vue.js** from Scratch\" series!\n\nThroughout this journey, we will construct a practical blog from the ground up using [**VitePress**](https:\u002F\u002Fvitepress.dev\u002F). We will explore a range of topics from initial configuration to deploying on **Cloudflare Pages**, including:\n\n- **Getting Started with VitePress: Project Setup and Essentials**: Learn to set up a fresh **VitePress project** by incorporating [**Tailwind CSS**](https:\u002F\u002Ftailwindcss.com\u002F) and [**unplugin-vue-components**](https:\u002F\u002Fgithub.com\u002Funplugin\u002Funplugin-vue-components) for an enhanced development process.\n- **From Default to Custom: Building a VitePress Blog Theme**: We will entirely remove the default theme and create a personalized theme. _You'll be surprised by its simplicity!_\n- **Optimize Your VitePress Blog's Architecture Design**: Discover how to organize code and design your blog for scalability and maintainability.\n- **Implementing Blog Index with VitePress and Tailwind CSS**: Create a list of blog posts. This will introduce [**data loaders from VitePress**](https:\u002F\u002Fvitepress.dev\u002Fguide\u002Fdata-loading).\n- **Single Blog Rendering in VitePress with Tailwind Typography**: Create a page dedicated to reading each blog post.\n- **Deploy VitePress Blog Globally with Cloudflare Pages**: Integrate **SEO metadata** for improved search engine visibility, eliminating the need for manual updates.\n- **Showcase Your GitHub Projects on Your VitePress Blog**: Develop a page to display your **GitHub** endeavors, extending the use of data loaders and demonstrating their flexibility.\n- **Creating Open Graph Images Automatically for Each Blog Post**: Efficiently create **Open Graph images** for each post, saving time and enhancing appeal.\n- **Deploy VitePress Blog Globally with Cloudflare Pages**: Seamlessly deploy your blog to [**Cloudflare Pages**](https:\u002F\u002Fpages.cloudflare.com\u002F), achieving this in just a few clicks!\n- **Ensure Blog Quality with Playwright Automated Testing**: Implement **end-to-end testing** with [**Playwright**](https:\u002F\u002Fplaywright.dev\u002F) to ensure your blog functions as expected.\n- **An Internal Refactor for the Future Growth of our Blog**: Prepare your blog for future growth by refactoring the codebase, ensuring it remains maintainable and scalable.\n- **Migrating Our VitePress Blog to Tailwind CSS Version 4**: Upgrade our blog to the latest version of **Tailwind CSS** to leverage its new features and improvements.\n\nBy the conclusion, you will possess a fully operational and captivating **blog**, allowing you to concentrate exclusively on producing **content**, which is paramount. Simply write and publish, as the blog will autonomously manage the rest.\n\n![Home Page of our Blog](\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fdeploy-vitepress-blog-globally-with-cloudflare-pages\u002Fvitepress-home.png)\n\nThis series offers a detailed, step-by-step **guide**. Rest assured, each aspect will be thoroughly elucidated, from selecting to implementing every feature. While each feature will be minimal and focused on the core, this does not mean we will forgo creating a visually pleasing and functional blog.\n\nShould you have any inquiries, please feel free to engage in the comments section under each article.\n\nI hope you find this series truly enjoyable! 🚀\n\n## Chapters\n\n::series-chapters-list\n---\nclass: mx-auto max-w-5xl\n---\n::\n",{"title":2257,"description":2472},{"loc":2478,"images":2482},[2483],{"loc":2440},"series\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch","A new perspective on blogging with VitePress and Vue.js",[2487,2066,2427],"vuejs","H9cubHgLKM0Siblzkwf7mDsFVYr2CLbh_ciFOpQrSVk",[2490,2496,2502,2504,2510,2516,2523,2529,2535,2541,2547,2554],{"contentId":2491,"title":2296,"description":2492,"path":2493,"part":100,"github":2494,"topics":2245},"b1b99d95-ac6d-4f25-a121-0851988102a2","From setup to styling with Tailwind CSS and automatic Vue imports, build your content-driven site effortlessly.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fgetting-started-with-vitepress-project-setup-and-essentials",{"branch":2495},"01.project-initialization",{"contentId":2497,"title":2318,"description":2498,"path":2499,"part":118,"github":2500,"topics":2245},"172f2a41-2f7c-44e9-855d-322adc536279","Step-by-step VitePress theme customization: guide to building a unique theme layout, adding Markdown content, and removing defaults.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Ffrom-default-to-custom-building-a-vitepress-blog-theme",{"branch":2501},"02.the-basics-for-a-custom-theme",{"contentId":2240,"title":5,"description":2242,"path":2247,"part":125,"github":2503,"topics":2245},{"branch":2244},{"contentId":2505,"title":2333,"description":2506,"path":2507,"part":141,"github":2508,"topics":2245},"4d93a3c5-f3ff-4ff6-a569-5234ef805850","Learn to create a list of blog articles using VitePress, a crucial feature for any content-centric website. Utilize data loaders to load articles.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fimplementing-blog-index-with-vitepress-and-tailwind-css",{"branch":2509},"04.comprehensive-guide-to-listing-blog-articles",{"contentId":2511,"title":2346,"description":2512,"path":2513,"part":153,"github":2514,"topics":2245},"15b9a49c-b9fb-4d76-a08d-2acaf55ff205","Enhance your VitePress blog with Tailwind Typography. Learn to render markdown beautifully with syntax highlights.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fsingle-blog-rendering-in-vitepress-with-tailwind-typography",{"branch":2515},"05.read-a-single-blog-article",{"contentId":2517,"title":2518,"description":2519,"path":2520,"part":158,"github":2521,"topics":2245},"66af9aaf-d6d3-4151-a51b-806835988340","Enhance Website Visibility: SEO Metadata and Sitemap","Enhance website traffic through strategic SEO metadata and sitemaps for improved indexing. Learn how to automate metadata generation for each page.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fenhance-website-visibility-seo-metadata-and-sitemap",{"branch":2522},"06.seo-metadata-and-sitemap",{"contentId":2524,"title":2362,"description":2525,"path":2526,"part":165,"github":2527,"topics":2245},"a4a933b8-07a5-4587-ad54-c3f9e30cbf45","Enhance your VitePress blog with GitHub projects. Learn API data retrieval and how to display your projects on your blog.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fshowcase-your-github-projects-on-your-vitepress-blog",{"branch":2528},"07.showcase-your-github-projects",{"contentId":2530,"title":2372,"description":2531,"path":2532,"part":367,"github":2533,"topics":2245},"c76a349e-a495-4890-ab05-3e8b6bb90add","Learn how to dynamically generate Open Graph images for each blog post, enhancing the visual appeal when sharing content on social media.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fcreating-open-graph-images-automatically-for-each-blog-post",{"branch":2534},"08.automatically-generated-open-graph-images",{"contentId":2536,"title":2352,"description":2537,"path":2538,"part":373,"github":2539,"topics":2245},"c05ae463-c5ae-4c43-872d-bb05263c7f74","Deploy the blog to Cloudflare Pages for global accessibility. Discover how to deploy the blog to Cloudflare Pages and share it worldwide with ease.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fdeploy-vitepress-blog-globally-with-cloudflare-pages",{"branch":2540},"09.share-the-blog-globally",{"contentId":2542,"title":2394,"description":2543,"path":2544,"part":379,"github":2545,"topics":2245},"aa5392e0-6287-4673-9365-34313f0af1fa","Enhance web development with Playwright-induced automated testing. Elevate blog quality through comprehensive end-to-end and SEO tests.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fensure-blog-quality-with-playwright-automated-testing",{"branch":2546},"10.automate-testing",{"contentId":2548,"title":2549,"description":2550,"path":2551,"part":385,"github":2552,"topics":2245},"5b1b6117-14f0-4f1d-ba13-5b3583f341bf","An Internal Refactor for the Future Growth of Our Blog","Prepare your blog for future growth by refactoring the codebase to ensure it remains maintainable and scalable.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fan-internal-refactor-for-the-future-growth-of-our-blog",{"branch":2553},"11.internal-refactor",{"contentId":2555,"title":2417,"description":2556,"path":2557,"part":391,"github":2558,"topics":2245},"3499bbd1-20a6-43f0-9bb7-be1da2bb6eac","A step-by-step guide on upgrading our VitePress blog to Tailwind CSS 4.0 to leverage its latest features and improvements.","\u002Fseries\u002Fcreate-a-blog-with-vitepress-and-vue-js-from-scratch\u002Fmigrating-our-vitepress-blog-to-tailwind-css-version-4",{"branch":2559},"12.migration-to-tailwind-css-4",1795016692129]