如何使用vite将生产脚本和css注入到索引html中?

Gri*_*zly 5 javascript config reactjs vite

我的vite.config.ts是:

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
    plugins: [react()],
    publicDir: './src/assets',
    build: {
        lib: {
            entry: './src/main.tsx',
            name: 'index',
            fileName: 'index',
            formats: ['iife']
        }
    },
    server: {
        host: true
    }
});
Run Code Online (Sandbox Code Playgroud)

如何在 html 索引中自动注入生产脚本和 css?

就像 webpack 对 html-webpack-plugin 所做的那样。

我是 vite 新手(也是 webpack 哈哈),至少我找不到任何配置可以让我做类似的事情,有办法做到吗?

我希望你能帮助我c:

ele*_*vir 1

听起来你需要的是vite-plugin-singlefile