From 959f8dfd5e65892f537ca1674d63cb205e9f3630 Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 29 Jun 2024 20:25:24 -0400 Subject: [PATCH] Updated build to be more treeshakeable, added CSS generation --- lib/{main.ts => index.ts} | 0 package-lock.json | 166 +++++++++++++++++++++++++++++++++++++- package.json | 19 ++--- vite.config.ts | 19 ++++- 4 files changed, 188 insertions(+), 16 deletions(-) rename lib/{main.ts => index.ts} (100%) diff --git a/lib/main.ts b/lib/index.ts similarity index 100% rename from lib/main.ts rename to lib/index.ts diff --git a/package-lock.json b/package-lock.json index af65694..752280f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@erjdev/vite-react-components", - "version": "0.1.7", + "version": "0.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@erjdev/vite-react-components", - "version": "0.1.7", + "version": "0.2.0", "devDependencies": { "@types/node": "^20.14.9", "@types/react": "^18.3.3", @@ -21,6 +21,7 @@ "typescript": "^5.2.2", "vite": "^5.3.1", "vite-plugin-dts": "^3.9.1", + "vite-plugin-lib-inject-css": "^2.1.1", "vitest": "^1.6.0" }, "peerDependencies": { @@ -28,6 +29,153 @@ "react-dom": "^18.3.1" } }, + "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/parser": { "version": "7.24.7", "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.24.7.tgz", @@ -4020,6 +4168,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/vitest": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/vitest/-/vitest-1.6.0.tgz", diff --git a/package.json b/package.json index da35220..307d4be 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,15 @@ { "name": "@erjdev/vite-react-components", - "version": "0.1.8", + "version": "0.2.0", "type": "module", "files": [ - "dist/" + "dist" + ], + "types": "./dist/index.d.ts", + "module": "./dist/index.js", + "sideEffects": [ + "**/*.css" ], - "types": "./dist/vrc.es.d.ts", - "module": "./dist/vrc.es.js", - "exports": { - ".": { - "import": "./dist/vrc.es.js", - "types": "./dist/vrc.es.d.ts" - }, - "./dist/style.css": "./dist/style.css" - }, "repository": { "type": "git", "url": "git+https://github.com/erjdev/vite-react-components.git" @@ -43,6 +39,7 @@ "typescript": "^5.2.2", "vite": "^5.3.1", "vite-plugin-dts": "^3.9.1", + "vite-plugin-lib-inject-css": "^2.1.1", "vitest": "^1.6.0" }, "publishConfig": { diff --git a/vite.config.ts b/vite.config.ts index 8a91284..90022b0 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,16 +3,18 @@ import { defineConfig } from 'vite' import react from '@vitejs/plugin-react-swc' import path, { resolve } from 'path' import dts from 'vite-plugin-dts'; +import { libInjectCss } from 'vite-plugin-lib-inject-css'; // https://vitejs.dev/config/ export default defineConfig({ plugins: [ react(), dts({ - include: ['lib'], + include: ['lib'], tsconfigPath: 'tsconfig.lib.json', rollupTypes: true, }), + libInjectCss(), ], server: { port: 3000, @@ -20,7 +22,12 @@ export default defineConfig({ build: { copyPublicDir: false, lib: { - entry: resolve(__dirname, 'lib/main.ts'), + entry: { + index: resolve(__dirname, 'lib/index.ts'), + button: resolve(__dirname, 'lib/components/Button/index.tsx'), + input: resolve(__dirname, 'lib/components/Input/index.tsx'), + label: resolve(__dirname, 'lib/components/Label/index.tsx'), + }, formats: ['es'], name: 'ViteReactComponents', fileName: (format) => `vrc.${format}.js`, @@ -28,6 +35,12 @@ export default defineConfig({ rollupOptions: { external: ['react', 'react/jsx-runtime', 'react-dom'], output: { + // Put chunk files at /chunks + chunkFileNames: 'chunks/[name].[hash].js', + // Put chunk styles at /assets + assetFileNames: 'assets/[name][extname]', + entryFileNames: '[name].js', + // Register externals/globals globals: { react: "React", "react-dom": "ReactDOM", @@ -42,6 +55,6 @@ export default defineConfig({ }, }, test: { - include: ['./vitest/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'] + include: ['./vitest/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'], }, });