From d7bcb182eb5874e26bf483f325be86fb4046efdd Mon Sep 17 00:00:00 2001 From: Tyler J Cvetan Date: Sat, 15 Jun 2024 18:38:48 -0500 Subject: [PATCH] feat: update sdk to build as vite lib --- package-lock.json | 187 +++++++++++++++++++++++++++++++++++- packages/sdk/package.json | 25 ++++- packages/sdk/vite.config.ts | 25 +++++ 3 files changed, 230 insertions(+), 7 deletions(-) create mode 100644 packages/sdk/vite.config.ts diff --git a/package-lock.json b/package-lock.json index 8b448a9..250de85 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,6 +31,153 @@ "npm": "^10.7.0" } }, + "node_modules/@ast-grep/napi": { + "version": "0.22.6", + "resolved": "https://registry.npmjs.org/@ast-grep/napi/-/napi-0.22.6.tgz", + "integrity": "sha512-kNF87HiI4omHC7VzyBZSvqOAXtMlSDRF2YX+O5ya0XKv/7/GYms1opLQ+BQ9twLLDj0WsSFX4MYg0TrinZTxTg==", + "dev": true, + "engines": { + "node": ">= 10" + }, + "optionalDependencies": { + "@ast-grep/napi-darwin-arm64": "0.22.6", + "@ast-grep/napi-darwin-x64": "0.22.6", + "@ast-grep/napi-linux-arm64-gnu": "0.22.6", + "@ast-grep/napi-linux-x64-gnu": "0.22.6", + "@ast-grep/napi-linux-x64-musl": "0.22.6", + "@ast-grep/napi-win32-arm64-msvc": "0.22.6", + "@ast-grep/napi-win32-ia32-msvc": "0.22.6", + "@ast-grep/napi-win32-x64-msvc": "0.22.6" + } + }, + "node_modules/@ast-grep/napi-darwin-arm64": { + "version": "0.22.6", + "resolved": "https://registry.npmjs.org/@ast-grep/napi-darwin-arm64/-/napi-darwin-arm64-0.22.6.tgz", + "integrity": "sha512-L9rEGJ8fNi5LxbZj860wbXxjX7DLNV799zcTaPOSzYadvNyhMY3LWvDXd45Vtx6Dh8QRtCoEMQmw8KaRCEjm9A==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@ast-grep/napi-darwin-x64": { + "version": "0.22.6", + "resolved": "https://registry.npmjs.org/@ast-grep/napi-darwin-x64/-/napi-darwin-x64-0.22.6.tgz", + "integrity": "sha512-0iuM6iDJNhcPd6a/JJr64AallR7ttGW/MvUujfQdvJEZY5p9LK35xm23dULznW0tIMgwtMKPRaprgk8LPondKg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@ast-grep/napi-linux-arm64-gnu": { + "version": "0.22.6", + "resolved": "https://registry.npmjs.org/@ast-grep/napi-linux-arm64-gnu/-/napi-linux-arm64-gnu-0.22.6.tgz", + "integrity": "sha512-9PAqNJlAQfFm1RW0DVCM/S4gFHdppxUTWacB3qEeJZXgdLnoH0KGQa4z3Xo559SPYDKZy0VnY02mZ3XJ+v6/Vw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@ast-grep/napi-linux-x64-gnu": { + "version": "0.22.6", + "resolved": "https://registry.npmjs.org/@ast-grep/napi-linux-x64-gnu/-/napi-linux-x64-gnu-0.22.6.tgz", + "integrity": "sha512-nZf+gxXVrZqvP1LN6HwzOMA4brF3umBXfMequQzv8S6HeJ4c34P23F0Tw8mHtQpVYP9PQWJUvt3LJQ8Xvd5Hiw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@ast-grep/napi-linux-x64-musl": { + "version": "0.22.6", + "resolved": "https://registry.npmjs.org/@ast-grep/napi-linux-x64-musl/-/napi-linux-x64-musl-0.22.6.tgz", + "integrity": "sha512-gcJeBMgJQf2pZZo0lgH0Vg4ycyujM7Am8VlomXhavC/dPpkddA1tiHSIC4fCNneLU1EqHITy3ALSmM4GLdsjBw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@ast-grep/napi-win32-arm64-msvc": { + "version": "0.22.6", + "resolved": "https://registry.npmjs.org/@ast-grep/napi-win32-arm64-msvc/-/napi-win32-arm64-msvc-0.22.6.tgz", + "integrity": "sha512-YDDzvPIyl4ti8xZfjvGSGVCX9JJjMQjyWPlXcwRpiLRnHThtHTDL8PyE2yq+gAPuZ28QbrygMkP9EKXIyYFVcQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@ast-grep/napi-win32-ia32-msvc": { + "version": "0.22.6", + "resolved": "https://registry.npmjs.org/@ast-grep/napi-win32-ia32-msvc/-/napi-win32-ia32-msvc-0.22.6.tgz", + "integrity": "sha512-w5P0MDcBD3bifC2K9nCDEFYacy8HQnXdf6fX6cIE/7xL8XEDs6D1lQjGewrZDcMAXVXUQfupj4P27ZsJRmuIoQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@ast-grep/napi-win32-x64-msvc": { + "version": "0.22.6", + "resolved": "https://registry.npmjs.org/@ast-grep/napi-win32-x64-msvc/-/napi-win32-x64-msvc-0.22.6.tgz", + "integrity": "sha512-1aaHvgsCBwUP0tDf4HXPMpUV/nUwsOWgRCiBc2zIJjdEjT9TTk795EIX9Z1Nc0OMCrxVEceyiKcYTofXa0Fpxw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, "node_modules/@babel/code-frame": { "version": "7.24.7", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", @@ -667,6 +814,12 @@ "deprecated": "Use @eslint/object-schema instead", "dev": true }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.4.15", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", + "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==", + "dev": true + }, "node_modules/@mantine/core": { "version": "7.10.2", "resolved": "https://registry.npmjs.org/@mantine/core/-/core-7.10.2.tgz", @@ -5707,6 +5860,15 @@ "node": "14 || >=16.14" } }, + "node_modules/magic-string": { + "version": "0.30.10", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.10.tgz", + "integrity": "sha512-iIRwTIf0QKV3UAnYK4PU8uiEc4SRh5jX0mwpIwETPpHdhVM4f53RSwS/vXvN1JhGX+Cs7B8qIq3d6AH49O5fAQ==", + "dev": true, + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.4.15" + } + }, "node_modules/marked": { "version": "12.0.2", "resolved": "https://registry.npmjs.org/marked/-/marked-12.0.2.tgz", @@ -11555,9 +11717,9 @@ } }, "node_modules/vite": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/vite/-/vite-5.3.0.tgz", - "integrity": "sha512-hA6vAVK977NyW1Qw+fLvqSo7xDPej7von7C3DwwqPRmnnnK36XEBC/J3j1V5lP8fbt7y0TgTKJbpNGSwM+Bdeg==", + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/vite/-/vite-5.3.1.tgz", + "integrity": "sha512-XBmSKRLXLxiaPYamLv3/hnP/KXDai1NDexN0FpkTaZXTfycHvkRHoenpgl/fvuK/kPbB6xAgoyiryAhQNxYmAQ==", "dev": true, "dependencies": { "esbuild": "^0.21.3", @@ -11609,6 +11771,20 @@ } } }, + "node_modules/vite-plugin-lib-inject-css": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/vite-plugin-lib-inject-css/-/vite-plugin-lib-inject-css-2.1.1.tgz", + "integrity": "sha512-RIMeVnqBK/8I0E9nnQWzws6pdj5ilRMPJSnXYb6nWxNR4EmDPnksnb/ACoR5Fy7QfzULqS4gtQMrjwnNCC9zoA==", + "dev": true, + "dependencies": { + "@ast-grep/napi": "^0.22.3", + "magic-string": "^0.30.10", + "picocolors": "^1.0.0" + }, + "peerDependencies": { + "vite": "*" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -11879,8 +12055,11 @@ "devDependencies": { "@swc/cli": "^0.3.12", "@swc/core": "^1.5.28", + "@vitejs/plugin-react-swc": "^3.7.0", "prettier": "3.3.2", - "typescript": "^5.4.5" + "typescript": "^5.4.5", + "vite": "^5.3.1", + "vite-plugin-lib-inject-css": "^2.1.1" } } } diff --git a/packages/sdk/package.json b/packages/sdk/package.json index f425573..af4d81c 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -5,11 +5,27 @@ "description": "", "license": "MIT", "author": "Tyler J Cvetan", + "sideEffects": [ + "**/*.css" + ], "type": "module", - "main": "dist/index.js", + "exports": { + ".": { + "import": { + "default": "./dist/@somethingsexy/sdk.es.js" + }, + "require": { + "default": "./dist/@somethingsexy/sdk.umd.js" + } + }, + "./styles.css": "./dist/index.css" + }, + "main": "./dist/@somethingsexy/sdk.umd.js", + "module": "./dist/@somethingsexy/sdk.es.js", "types": "dist/index.d.ts", "scripts": { - "build": "swc ./src -d dist --strip-leading-paths", + "build": "vite build", + "build:old": "swc ./src -d dist --strip-leading-paths", "build:watch": "swc ./src -d dist -w --strip-leading-paths", "lint": "eslint ./src --report-unused-disable-directives --max-warnings 0 --no-warn-ignored", "lint:fix": "eslint ./src --report-unused-disable-directives --max-warnings 0 --no-warn-ignored --fix", @@ -32,7 +48,10 @@ "devDependencies": { "@swc/cli": "^0.3.12", "@swc/core": "^1.5.28", + "@vitejs/plugin-react-swc": "^3.7.0", "prettier": "3.3.2", - "typescript": "^5.4.5" + "typescript": "^5.4.5", + "vite": "^5.3.1", + "vite-plugin-lib-inject-css": "^2.1.1" } } diff --git a/packages/sdk/vite.config.ts b/packages/sdk/vite.config.ts new file mode 100644 index 0000000..53e1da5 --- /dev/null +++ b/packages/sdk/vite.config.ts @@ -0,0 +1,25 @@ +import { defineConfig } from 'vite' +import { libInjectCss } from 'vite-plugin-lib-inject-css' +import path from 'path' +import react from '@vitejs/plugin-react-swc' + +export default defineConfig({ + plugins: [react(), libInjectCss()], + build: { + lib: { + entry: path.resolve(__dirname, 'src/index.ts'), + name: '@somethingsexy/sdk', + fileName: (format) => `@somethingsexy/sdk.${format}.js`, + }, + rollupOptions: { + external: ['react', 'react/jsx-runtime', 'react-dom'], + output: { + globals: { + react: 'react', + 'react-dom': 'ReactDOM', + 'react/jsx-runtime': 'react/jsx-runtime', + }, + }, + }, + }, +})