Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

308
Visualizações
What is the purpose of the 'main.js' file in a Vite.js app?

I am building a Vite.js app and am not sure I understand the purpose of the main.js file. I am having a hard time finding a clear explanation of this in the vite docs. I found an S/O post with a similar question in regards to a Vue app, but am not sure if the answers apply to Vite as well.

I am new to working with these frontend build tools, as well as modules in general, and want to make sure I understand what's happening. I know that index.html serves as the entry point to the app during development, but what is the purpose of main.js exactly?

My file structure is as follows:

├── package.json
├── vite.config.js
├── index.html
├── main.js
├── styles.css
├── pages
│   ├── login
│   │   ├── login.html
│   │   ├── login.js
│   ├── home
│   │   ├── home.html 
│   │   ├── home.js
│   │     
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In the main.js you create the app instance, configure it and then mount it to a divtag. This is the way forward for any vue3 application and is independent on the bundling tool used (such as vite). A typical example for a main.jsis as follows:

import {createApp} from 'vue'

import store from './store.js'
import router from './routes.js'
import i18n from './i18n.js'
import App from '../components/App.vue'


// mount is the last one ...
const myApp = createApp(App);
myApp.use(store)
    .use(router)
    .use(i18n)
    .mount('#app');

In the index.html you would load this main.js:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>MyApp</title>
    <link rel="icon" href="/favicon.svg" type="image/svg+xml">
    <meta name="theme-color" content="#ffffff">
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/js/main.js"></script>
</body>
</html>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda