[{"data":1,"prerenderedAt":341},["ShallowReactive",2],{"blog-en-\u002Fblog\u002Forganizacao-main-js-vue":3},{"id":4,"title":5,"body":6,"date":329,"description":330,"extension":331,"meta":332,"navigation":152,"path":333,"seo":334,"stem":335,"tags":336,"__hash__":340},"blog_en\u002Fblog\u002Forganizacao-main-js-vue.md","Organizing main.js in a Vue application",{"type":7,"value":8,"toc":324},"minimark",[9,18,23,66,70,268,272,320],[10,11,12,13,17],"p",{},"Best practices for organizing the ",[14,15,16],"code",{},"main.js"," file of a Vue application, with an example evaluated practice by practice.",[19,20,22],"h2",{"id":21},"best-practices-for-organizing-mainjs","Best practices for organizing main.js",[24,25,26,34,41,47,54,57,60,63],"ol",{},[27,28,29,30,33],"li",{},"Import the dependencies: It's important to import all the necessary dependencies, such as Vue, ",[14,31,32],{},"App.vue",", the router, etc.",[27,35,36,37,40],{},"Configure and register plugins: Registering plugins, such as ",[14,38,39],{},"VueToast",", is also good practice.",[27,42,43,44,40],{},"Configure Vue options: Configuring options, such as ",[14,45,46],{},"productionTip",[27,48,49,50,53],{},"Instantiate Vue: This means instantiating it with the router and the renderer, mounting the instance on the ",[14,51,52],{},"#app"," element.",[27,55,56],{},"Organizing the file: Use spacing and comments to make the code more readable and easier to understand.",[27,58,59],{},"Keep the file simple: Avoid adding too many components and complex logic to the main file. Instead, split them into smaller, easier-to-manage files.",[27,61,62],{},"Use good coding practices: Use good coding practices, such as avoiding duplicated code and using global variables sparingly.",[27,64,65],{},"Use design patterns: Use patterns such as the data flow pattern and the component pattern to keep the code structure clean and easy to understand.",[19,67,69],{"id":68},"code-example","Code example",[71,72,77],"pre",{"className":73,"code":74,"language":75,"meta":76,"style":76},"language-js shiki shiki-themes darcula","import Vue from \"vue\";\nimport App from \".\u002FApp.vue\";\nimport router from \".\u002Frouter\";\nimport VueToast from \"vue-toast-notification\";\n\nimport \"vue-toast-notification\u002Fdist\u002Ftheme-sugar.css\";\n\nVue.use(VueToast);\n\nVue.config.productionTip = false;\n\nnew Vue({\n  router,\n  render: (h) => h(App),\n}).$mount(\"#app\");\n","js","",[14,78,79,102,117,132,147,154,164,169,182,187,209,214,226,232,250],{"__ignoreMap":76},[80,81,84,88,92,95,99],"span",{"class":82,"line":83},"line",1,[80,85,87],{"class":86},"sYMgc","import",[80,89,91],{"class":90},"sE2CK"," Vue ",[80,93,94],{"class":86},"from",[80,96,98],{"class":97},"sZ3PO"," \"vue\"",[80,100,101],{"class":90},";\n",[80,103,105,107,110,112,115],{"class":82,"line":104},2,[80,106,87],{"class":86},[80,108,109],{"class":90}," App ",[80,111,94],{"class":86},[80,113,114],{"class":97}," \".\u002FApp.vue\"",[80,116,101],{"class":90},[80,118,120,122,125,127,130],{"class":82,"line":119},3,[80,121,87],{"class":86},[80,123,124],{"class":90}," router ",[80,126,94],{"class":86},[80,128,129],{"class":97}," \".\u002Frouter\"",[80,131,101],{"class":90},[80,133,135,137,140,142,145],{"class":82,"line":134},4,[80,136,87],{"class":86},[80,138,139],{"class":90}," VueToast ",[80,141,94],{"class":86},[80,143,144],{"class":97}," \"vue-toast-notification\"",[80,146,101],{"class":90},[80,148,150],{"class":82,"line":149},5,[80,151,153],{"emptyLinePlaceholder":152},true,"\n",[80,155,157,159,162],{"class":82,"line":156},6,[80,158,87],{"class":86},[80,160,161],{"class":97}," \"vue-toast-notification\u002Fdist\u002Ftheme-sugar.css\"",[80,163,101],{"class":90},[80,165,167],{"class":82,"line":166},7,[80,168,153],{"emptyLinePlaceholder":152},[80,170,172,175,179],{"class":82,"line":171},8,[80,173,174],{"class":90},"Vue.",[80,176,178],{"class":177},"s2lgc","use",[80,180,181],{"class":90},"(VueToast);\n",[80,183,185],{"class":82,"line":184},9,[80,186,153],{"emptyLinePlaceholder":152},[80,188,190,192,196,199,201,204,207],{"class":82,"line":189},10,[80,191,174],{"class":90},[80,193,195],{"class":194},"sk7qV","config",[80,197,198],{"class":90},".",[80,200,46],{"class":194},[80,202,203],{"class":90}," = ",[80,205,206],{"class":86},"false",[80,208,101],{"class":90},[80,210,212],{"class":82,"line":211},11,[80,213,153],{"emptyLinePlaceholder":152},[80,215,217,220,223],{"class":82,"line":216},12,[80,218,219],{"class":86},"new",[80,221,222],{"class":177}," Vue",[80,224,225],{"class":90},"({\n",[80,227,229],{"class":82,"line":228},13,[80,230,231],{"class":90},"  router,\n",[80,233,235,238,241,244,247],{"class":82,"line":234},14,[80,236,237],{"class":177},"  render",[80,239,240],{"class":90},": (h) ",[80,242,243],{"class":86},"=>",[80,245,246],{"class":177}," h",[80,248,249],{"class":90},"(App),\n",[80,251,253,256,259,262,265],{"class":82,"line":252},15,[80,254,255],{"class":90},"}).",[80,257,258],{"class":177},"$mount",[80,260,261],{"class":90},"(",[80,263,264],{"class":97},"\"#app\"",[80,266,267],{"class":90},");\n",[19,269,271],{"id":270},"best-practices-followed-in-the-example","Best practices followed in the example",[273,274,275,284,294,303,308,311,314,317],"ul",{},[27,276,277,278,280,281,283],{},"Import the dependencies: The code imports Vue, ",[14,279,32],{},", the router and ",[14,282,39],{},", which are the dependencies needed for the application to work.",[27,285,286,287,290,291,293],{},"Configure and register plugins: The code uses the ",[14,288,289],{},"Vue.use(VueToast)"," command to register and configure the ",[14,292,39],{}," plugin.",[27,295,296,297,300,301,198],{},"Configure Vue options: The code sets the ",[14,298,299],{},"Vue.config.productionTip"," option to ",[14,302,206],{},[27,304,305,306,53],{},"Instantiate Vue: The code instantiates Vue with the router and the renderer, and mounts the instance on the ",[14,307,52],{},[27,309,310],{},"Organizing the file: The code uses spacing to make it more readable.",[27,312,313],{},"Keep the file simple: The code is simple and doesn't add too many components or complex logic to the main file.",[27,315,316],{},"Use good coding practices: The code has no duplicated code and uses global variables sparingly.",[27,318,319],{},"Use design patterns: The code doesn't explicitly specify which design patterns are being followed, but its simple, organized structure suggests some pattern is being applied.",[321,322,323],"style",{},"html pre.shiki code .sYMgc, html code.shiki .sYMgc{--shiki-default:#CC7832}html pre.shiki code .sE2CK, html code.shiki .sE2CK{--shiki-default:#A9B7C6}html pre.shiki code .sZ3PO, html code.shiki .sZ3PO{--shiki-default:#6A8759}html pre.shiki code .s2lgc, html code.shiki .s2lgc{--shiki-default:#FFC66D}html pre.shiki code .sk7qV, html code.shiki .sk7qV{--shiki-default:#9876AA}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);}",{"title":76,"searchDepth":104,"depth":104,"links":325},[326,327,328],{"id":21,"depth":104,"text":22},{"id":68,"depth":104,"text":69},{"id":270,"depth":104,"text":271},"2023-01-15","Study notes with best practices for organizing main.js in a Vue application: imports, plugins, configuration and an example evaluated practice by practice.","md",{},"\u002Fblog\u002Forganizacao-main-js-vue",{"title":5,"description":330},"blog\u002Forganizacao-main-js-vue",[337,338,339],"vue","architecture","fundamentals","2MnWvtzvqVDh4C7Oj2kek7elDKOYezB80R4YlLnZBWE",1794928449958]