From 5fc09d336d5ca33c1b1be552eac2d391df731ce2 Mon Sep 17 00:00:00 2001 From: Hyeonjong Date: Sat, 20 Jul 2024 21:17:00 +0900 Subject: [PATCH] Exports type of cjs module --- packages/tailwind-joy/vite.config.mjs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/tailwind-joy/vite.config.mjs b/packages/tailwind-joy/vite.config.mjs index b95311e..e7625db 100644 --- a/packages/tailwind-joy/vite.config.mjs +++ b/packages/tailwind-joy/vite.config.mjs @@ -1,3 +1,4 @@ +import { writeFileSync } from 'node:fs'; import { resolve } from 'node:path'; import { defineConfig } from 'vite'; import dts from 'vite-plugin-dts'; @@ -22,6 +23,17 @@ export default defineConfig({ dts({ entryRoot: 'src', include: ['src/**'], + afterBuild(emittedFiles) { + for (const [path, code] of emittedFiles) { + const extensionReplacedPath = path.replace(/\.d\.ts$/, '.d.cts'); + const extensionAddedCode = code.replace( + /(from '\.?\.(?:\/[^/;]+)*\/[^/;.]+)(';)/g, + '$1.cjs$2', + ); + + writeFileSync(extensionReplacedPath, extensionAddedCode); + } + }, }), react(), safelistGenerator(),