From 514a134203104c6f8ef41c12329ff7bd3a0a91d5 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Mon, 9 Oct 2023 14:28:09 -0400 Subject: [PATCH] refactor: update to not bundle but instead chunk using vite-plugin-no-bundle --- npm-shrinkwrap.json | 11 +++++++++++ package.json | 4 ++-- vite.config.ts | 14 +++++++------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index f638365..ab818c4 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -62,6 +62,7 @@ "uniqid": "^5.4.0", "vite": "^4.4.11", "vite-plugin-dts": "^3.6.0", + "vite-plugin-no-bundle": "^3.0.0", "vite-plugin-node-polyfills": "^0.15.0", "vite-plugin-optimizer": "^1.4.2", "vite-plugin-scope-tailwind": "^1.1.3", @@ -28204,6 +28205,16 @@ } } }, + "node_modules/vite-plugin-no-bundle": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/vite-plugin-no-bundle/-/vite-plugin-no-bundle-3.0.0.tgz", + "integrity": "sha512-B8O4ZmWHbA8MWhsCqjcxwCLW5Kk2Q1Ax7JhZBBB/ort+DNONkBA2HND0d9lQ5d0Q+JSOMYAQDDQ1qAS1nmThyA==", + "dev": true, + "dependencies": { + "fast-glob": "^3.2.12", + "micromatch": "^4.0.5" + } + }, "node_modules/vite-plugin-node-polyfills": { "version": "0.15.0", "resolved": "https://registry.npmjs.org/vite-plugin-node-polyfills/-/vite-plugin-node-polyfills-0.15.0.tgz", diff --git a/package.json b/package.json index ba54038..64440be 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,7 @@ "name": "@lumeweb/sdk", "version": "0.1.0-develop.3", "type": "module", - "main": "lib/lib.umd.js", - "module": "lib/lib.es.js", + "main": "lib/index.js", "types": "lib/index.d.ts", "repository": { "type": "git", @@ -74,6 +73,7 @@ "uniqid": "^5.4.0", "vite": "^4.4.11", "vite-plugin-dts": "^3.6.0", + "vite-plugin-no-bundle": "^3.0.0", "vite-plugin-node-polyfills": "^0.15.0", "vite-plugin-optimizer": "^1.4.2", "vite-plugin-scope-tailwind": "^1.1.3", diff --git a/vite.config.ts b/vite.config.ts index 6cf4d29..6280c73 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,8 +4,8 @@ import scopeTailwind from "vite-plugin-scope-tailwind"; import { resolve } from "path"; import svgr from "vite-plugin-svgr"; import dts from "vite-plugin-dts"; -import { nodePolyfills } from "vite-plugin-node-polyfills"; import optimizer from "vite-plugin-optimizer"; +import noBundlePlugin from "vite-plugin-no-bundle"; // https://vitejs.dev/config/ export default defineConfig({ @@ -20,11 +20,7 @@ export default defineConfig({ "node-fetch": "const e = undefined; export default e;export {e as Response, e as FormData, e as Blob};", }), - nodePolyfills({ - exclude: ["fs"], - globals: { Buffer: true, global: true, process: true }, - }), - // css({ output: 'styles/globals.css' }) + noBundlePlugin(), ], resolve: { dedupe: ["@lumeweb/libportal", "@lumeweb/libweb", "@lumeweb/libkernel"], @@ -45,9 +41,13 @@ export default defineConfig({ lib: { entry: resolve(__dirname, "src/index.ts"), name: "sdk", - fileName: (format) => `lib.${format}.js`, + fileName: "index", + formats: ["es"], }, rollupOptions: { + output: { + inlineDynamicImports: false, + }, external: ["react", "react-dom"], }, },