vite.config.js rollupOptions 指定多个入口文件

730 阅读1分钟

新人打包 vite vue 项目 发现只有index.html被打包进去,其他的html文件没有被打包进去。

可以这么写

export default defineConfig({
  plugins: [vue()],
  build: {
    rollupOptions: {
      input: ['./index.html', './index_b.html']
    }
  }
})

可以这么写

const entryPoints = ['./index.html', './index_b.html'];

const entryOutput = entryPoints.reduce((config, entry) => {
  config[entry.split('/').pop().split('.')[0]] = entry;
  return config;
}, {});

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: { 
    alias: { // 定义项目路径别名,这样可以在引入文件时,以属性值为起点
      '@': path.resolve(__dirname,'src/assets')
    }
  },
  build: {
    rollupOptions: {
      input: entryOutput
    }
  }
})