import { resolve } from "node:path"; import { defineConfig } from "vite"; import react from "@vitejs/plugin-react"; import dts from "unplugin-dts/vite"; import pkg from "./package.json" with { type: "json" }; import { genIndex, PluginOption } from "./vite-plugin/vite-plugin-gen-index.ts"; const genTsOption: PluginOption = { include: ["src/**/*.{tsx,ts,jsx,js}"], exclude: ["src/app.tsx", "src/main.tsx", "src/index.ts"], preamble: "export * from", entry: "src/index.ts", }; const genCssOption: PluginOption = { include: ["src/**/*.css"], exclude: ["src/index.css"], preamble: "@import", entry: "src/index.css", }; export default defineConfig({ plugins: [ genIndex(genTsOption, genCssOption), react(), dts({ outDirs: [ { dir: "dist", moduleFormat: "esm" }, { dir: "dist", moduleFormat: "cjs" }, ], bundleTypes: true, }), ], build: { target: "esnext", // Must write, vite/css-minify cannot recognize some ruler cssMinify: false, lib: { entry: resolve(import.meta.dirname, "src/index.ts"), name: "ui-react", formats: ["es", "cjs"], fileName: `index`, cssFileName: "index", }, rolldownOptions: { // make sure to externalize deps that shouldn't be bundled // into your library external: ["react/jsx-runtime", ...Object.keys(pkg.peerDependencies)], // output: { // assetFileNames: (assetInfo) => { // if (assetInfo.name && assetInfo.name.endsWith(".css")) { // return "index.css"; // } // return "[name].[hash][extname]"; // }, // // Provide global variables to use in the UMD build // // for externalized deps // globals: { // react: "React", // "react-dom": "ReactDOM", // }, // }, }, }, });