相关疑难解决方法(0)

如何使用vite2和vue3构建多页面应用?

vue.config.js我通过如下更改使用 Vue CLI 和 Vue 2 构建了一个多页面应用程序:

pages: {
    index: {
      entry: './src/pages/index/main.js',
      template: 'public/index.html',
      title: 'index page',
      chunks: ['chunk-vendors', 'chunk-common', 'index']
    },
    admin: {
      entry: './src/pages/admin/main.js',
      template: 'public/index.html',
      title: 'admin page',
      chunks: ['chunk-vendors', 'chunk-common', 'admin']
    }
},
...
Run Code Online (Sandbox Code Playgroud)

但是如何使用 Vite 和 Vue 3 构建多页面应用程序呢?

在此输入图像描述

这是我的目录结构。我像这样编辑了 vite.config.js:

import vue from '@vitejs/plugin-vue'
const { resolve } = require('path')
/**
 * @type {import('vite').UserConfig}
 */
export default {
  plugins: [vue()],
  build:{
    rollupOptions:{
      input:{
        main:resolve(__dirname,'index.html'),
        admin:resolve(__dirname,'src/admin/index.html')
      }
    }
  }
}

Run Code Online (Sandbox Code Playgroud)

但当我构建时它返回错误,并且我无法通过 localhost:3000/admin/index.html 打开管理页面。

vue.js vuejs3 vite

14
推荐指数
1
解决办法
2万
查看次数

标签 统计

vite ×1

vue.js ×1

vuejs3 ×1