/ vite.config.ts
vite.config.ts
1 import { defineConfig } from "vite"; 2 import { resolve } from "path"; 3 import dts from "vite-plugin-dts"; 4 import react from "@vitejs/plugin-react"; 5 import { libInjectCss } from "vite-plugin-lib-inject-css"; 6 import { extname, relative } from "path"; 7 import { fileURLToPath } from "node:url"; 8 import { globSync } from "glob"; 9 import svgr from "vite-plugin-svgr"; 10 11 // https://vitejs.dev/config/ 12 export default defineConfig({ 13 worker: { 14 rollupOptions: { 15 external: ["@codex-storage/sdk-js"], 16 output: { 17 globals: { 18 "@codex-storage/sdk-js": "codex-sdk-js", 19 }, 20 }, 21 }, 22 }, 23 plugins: [ 24 react(), 25 libInjectCss(), 26 dts({ 27 tsconfigPath: "./tsconfig.build.json", 28 rollupTypes: true, 29 }), 30 svgr({ 31 svgrOptions: { 32 plugins: ["@svgr/plugin-svgo", "@svgr/plugin-jsx"], 33 svgoConfig: { 34 floatPrecision: 2, 35 }, 36 }, 37 // ... 38 }) 39 ], 40 build: { 41 lib: { 42 entry: resolve(__dirname, "src/index.ts"), 43 formats: ["es"], 44 }, 45 sourcemap: true, 46 rollupOptions: { 47 external: [ 48 "react", 49 "react/jsx-runtime", 50 "@codex-storage/sdk-js", 51 ], 52 input: Object.fromEntries( 53 globSync("src/**/*.{ts,tsx}", { 54 ignore: ["src/**/*.d.ts"], 55 }) 56 .map((file) => [ 57 // The name of the entry point 58 // lib/nested/foo.ts becomes nested/foo 59 relative("src", file.slice(0, file.length - extname(file).length)), 60 // The absolute path to the entry file 61 // lib/nested/foo.ts becomes /project/lib/nested/foo.ts 62 fileURLToPath(new URL(file, import.meta.url)), 63 ]) 64 ), 65 output: { 66 assetFileNames: "assets/[name][extname]", 67 entryFileNames: "[name].js", 68 globals: { 69 "@codex-storage/sdk-js": "codex-sdk-js", 70 }, 71 }, 72 }, 73 }, 74 });