From e4bf8c7f3ded35fac41110d4cc65560baa2d7c7e Mon Sep 17 00:00:00 2001 From: Egor Didenko Date: Wed, 25 Sep 2024 15:29:52 -0400 Subject: [PATCH] feat(next): added new import for nextjs with ssr disabled --- packages/react-uploader/package.json | 16 ++++++++++------ .../Uploader/Inline/NextFileUploaderInline.ts | 6 ++++++ .../Uploader/Minimal/NextFileUploaderMinimal.ts | 6 ++++++ .../Uploader/Regular/NextFileUploaderRegular.ts | 6 ++++++ packages/react-uploader/src/nextjs.ts | 3 +++ packages/react-uploader/vite.config.js | 13 ++++++++----- 6 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 packages/react-uploader/src/Uploader/Inline/NextFileUploaderInline.ts create mode 100644 packages/react-uploader/src/Uploader/Minimal/NextFileUploaderMinimal.ts create mode 100644 packages/react-uploader/src/Uploader/Regular/NextFileUploaderRegular.ts create mode 100644 packages/react-uploader/src/nextjs.ts diff --git a/packages/react-uploader/package.json b/packages/react-uploader/package.json index c9380b2..e132ace 100644 --- a/packages/react-uploader/package.json +++ b/packages/react-uploader/package.json @@ -1,12 +1,10 @@ { "name": "@uploadcare/react-uploader", "description": "React component for file uploads using Uploadcare", - "version": "1.0.0", + "version": "1.1.0-alpha.1", "private": false, "type": "module", - "files": [ - "dist" - ], + "files": ["dist"], "main": "./dist/react-uploader.cjs", "module": "./dist/react-uploader.js", "types": "./dist/react-uploader.d.ts", @@ -15,7 +13,12 @@ "import": "./dist/react-uploader.js", "require": "./dist/react-uploader.cjs" }, - "./core.css": "./dist/libs.css" + "./next": { + "import": "./dist/nextjs.js", + "require": "./dist/nextjs.cjs", + "types": "./dist/nextjs.d.ts" + }, + "./core.css": "./dist/style.css" }, "scripts": { "dev": "tsc && vite build --watch", @@ -24,7 +27,8 @@ "test": "vitest" }, "peerDependencies": { - "@types/react": "17 || 18" + "@types/react": "17 || 18", + "next": "13 || 14" }, "dependencies": { "@uploadcare/file-uploader": "^1.2.0", diff --git a/packages/react-uploader/src/Uploader/Inline/NextFileUploaderInline.ts b/packages/react-uploader/src/Uploader/Inline/NextFileUploaderInline.ts new file mode 100644 index 0000000..0d257a6 --- /dev/null +++ b/packages/react-uploader/src/Uploader/Inline/NextFileUploaderInline.ts @@ -0,0 +1,6 @@ +import dynamic from "next/dynamic"; + +export const FileUploaderInline = dynamic( + () => import("./FileUploaderInline").then((mod) => mod.FileUploaderInline), + { ssr: false }, +); diff --git a/packages/react-uploader/src/Uploader/Minimal/NextFileUploaderMinimal.ts b/packages/react-uploader/src/Uploader/Minimal/NextFileUploaderMinimal.ts new file mode 100644 index 0000000..86e2550 --- /dev/null +++ b/packages/react-uploader/src/Uploader/Minimal/NextFileUploaderMinimal.ts @@ -0,0 +1,6 @@ +import dynamic from "next/dynamic"; + +export const FileUploaderMinimal = dynamic( + () => import("./FileUploaderMinimal").then((mod) => mod.FileUploaderMinimal), + { ssr: false }, +); diff --git a/packages/react-uploader/src/Uploader/Regular/NextFileUploaderRegular.ts b/packages/react-uploader/src/Uploader/Regular/NextFileUploaderRegular.ts new file mode 100644 index 0000000..25e3f9d --- /dev/null +++ b/packages/react-uploader/src/Uploader/Regular/NextFileUploaderRegular.ts @@ -0,0 +1,6 @@ +import dynamic from "next/dynamic"; + +export const FileUploaderRegular = dynamic( + () => import("./FileUploaderRegular").then((mod) => mod.FileUploaderRegular), + { ssr: false }, +); diff --git a/packages/react-uploader/src/nextjs.ts b/packages/react-uploader/src/nextjs.ts new file mode 100644 index 0000000..9637e52 --- /dev/null +++ b/packages/react-uploader/src/nextjs.ts @@ -0,0 +1,3 @@ +export { FileUploaderMinimal } from "./Uploader/Minimal/NextFileUploaderMinimal"; +export { FileUploaderRegular } from "./Uploader/Regular/NextFileUploaderRegular"; +export { FileUploaderInline } from "./Uploader/Inline/NextFileUploaderInline"; diff --git a/packages/react-uploader/vite.config.js b/packages/react-uploader/vite.config.js index c52749a..a0137b5 100644 --- a/packages/react-uploader/vite.config.js +++ b/packages/react-uploader/vite.config.js @@ -5,20 +5,23 @@ import dts from "vite-plugin-dts"; export default defineConfig({ build: { - cssCodeSplit: true, + cssCodeSplit: false, lib: { - entry: [resolve(__dirname, "src/libs.ts")], + entry: { + nextjs: resolve(__dirname, "src/nextjs.ts"), + "react-uploader": resolve(__dirname, "src/libs.ts"), + }, + name: "@uploadcare/react-uploader", formats: ["es", "cjs"], - - fileName: "react-uploader", }, rollupOptions: { - external: ["react", "@uploadcare/file-uploader"], + external: ["react", "next", "next/dynamic", "@uploadcare/file-uploader"], output: { globals: { react: "React", + next: "next", }, }, },