最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

vuejs3 - How to change entry file in Vue3, Vite? - Stack Overflow

programmeradmin1浏览0评论

I am using Vue3 & Vite. My question is, how can I configure entry point file of a page?

I have directory structure like this:

project_root
ㄴapps
  ㄴapp1
    ㄴpublic
      ㄴindex.html
  ㄴskeleton
    ㄴsrc
      ㄴmain.ts
...

index.html's body:

<body>
  <div id="app"></div>
</body>

main.ts:

const app = createApp(SomeApp);
app.mount('#app');

I would like to use app1's index.html file and use skeleton/src/main.ts. How can I do this?

When I was using Vue2, I configured multi-page in vue.config.js like this:

  pages: {
    index: {
      entry: '../skeleton/src/main.ts',
      template: 'public/index.html',
      filename: 'index.html',
      title: 'Some Title',
    },

I am using Vue3 & Vite. My question is, how can I configure entry point file of a page?

I have directory structure like this:

project_root
ㄴapps
  ㄴapp1
    ㄴpublic
      ㄴindex.html
  ㄴskeleton
    ㄴsrc
      ㄴmain.ts
...

index.html's body:

<body>
  <div id="app"></div>
</body>

main.ts:

const app = createApp(SomeApp);
app.mount('#app');

I would like to use app1's index.html file and use skeleton/src/main.ts. How can I do this?

When I was using Vue2, I configured multi-page in vue.config.js like this:

  pages: {
    index: {
      entry: '../skeleton/src/main.ts',
      template: 'public/index.html',
      filename: 'index.html',
      title: 'Some Title',
    },

Share Improve this question edited Nov 29, 2024 at 0:51 Rae asked Nov 28, 2024 at 9:53 RaeRae 53 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Your index.html is the entry point and everything else is resolved based to its location. You can check docs for a way to specify alternative root. Don't fet to move vite.config.ts to the same directory as index.html.

Location of your main.ts is specified in the index.html:

<div id="app"></div>
<script type="module" src="/src/main.ts"></script>

Location of App.vue is specified in the main.ts file. You can further explore config possibilities with, say, checking how docs describe configuration of multi-page apps: https://vite.dev/guide/build.html#multi-page-app

发布评论

评论列表(0)

  1. 暂无评论