Vite2 双页面的打包问题
发布于 2 年前 作者 chaoren 3264 次浏览 来自 问答
粉丝福利 : 关注VUE中文社区公众号,回复视频领取粉丝福利

按照官网(构建生产版本 | Vite 官方中文文档 设置了一下双页面,在开发模式下可以正常使用。
但是打包的时候报错了:

vite v2.1.5 building for production...
✓ 0 modules transformed.
Could not resolve entry module (project\index.html).
error during build:
Error: Could not resolve entry module (project\index.html).
    at error (D:\git2\vue-gitee\nf-plat-main\nf-plat-vite2-vue3\node_modules\rollup\dist\shared\rollup.js:5305:30)
    at ModuleLoader.loadEntryModule (D:\git2\vue-gitee\nf-plat-main\nf-plat-vite2-vue3\node_modules\rollup\dist\shared\rollup.js:18545:20)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async Promise.all (index 1)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

改成单页面就可以正常打包。所以问题肯定在双页面的设置的地方:

双页面,打包出错。开发环境正常。

// 打包配置
  build: {
    rollupOptions: {
      input: {
        main: resolve(__dirname, 'index.html'),
        nested: resolve(__dirname, 'project/index.html')
      }
    },
    target: 'modules',
    minify: 'terser' // 混淆器,terser构建后文件体积更小
  },

单页面,正常打包:

// 打包配置
  build: {
    rollupOptions: {
      input: {
        main: resolve(__dirname, 'index.html')
      }
    },
    target: 'modules',
    minify: 'terser' // 混淆器,terser构建后文件体积更小
  },

所以,还需要怎么设置?

回到顶部