From 5c24f98b6816770db30b57d7c66893e860c985a1 Mon Sep 17 00:00:00 2001 From: Carlos Martinho Date: Tue, 12 Mar 2024 20:48:12 +0000 Subject: [PATCH] fix: fix build issues on client side apps --- .changeset/quiet-maps-doubt.md | 5 +++++ package.json | 8 +++---- src/polyfills/index.ts | 5 ----- vite.config.js | 19 ++++++++++++---- vite.config.ts | 40 ---------------------------------- 5 files changed, 24 insertions(+), 53 deletions(-) create mode 100644 .changeset/quiet-maps-doubt.md delete mode 100644 vite.config.ts diff --git a/.changeset/quiet-maps-doubt.md b/.changeset/quiet-maps-doubt.md new file mode 100644 index 0000000..6ca7d4f --- /dev/null +++ b/.changeset/quiet-maps-doubt.md @@ -0,0 +1,5 @@ +--- +"@shadeprotocol/shadejs": patch +--- + +Fix build issues on client side applications diff --git a/package.json b/package.json index dafe325..ac30bc0 100644 --- a/package.json +++ b/package.json @@ -11,14 +11,14 @@ }, "license": "MIT", "type": "module", - "main": "./dist/shadejs.cjs", - "module": "./dist/shadejs.js", + "main": "./dist/index.umd.cjs", + "module": "./dist/index.js", "types": "./dist/index.d.ts", "exports": { ".": { "types": "./dist/index.d.ts", - "import": "./dist/shadejs.js", - "require": "./dist/shadejs.cjs" + "import": "./dist/index.js", + "require": "./dist/index.umd.cjs" } }, "files": [ diff --git a/src/polyfills/index.ts b/src/polyfills/index.ts index 0074b5f..4fd5657 100644 --- a/src/polyfills/index.ts +++ b/src/polyfills/index.ts @@ -1,7 +1,2 @@ // eslint-disable-next-line import/no-extraneous-dependencies import 'whatwg-fetch'; - -if (typeof window === 'undefined') { - // @ts-ignore - global.window = globalThis; -} diff --git a/vite.config.js b/vite.config.js index 0e2b16d..c86658e 100644 --- a/vite.config.js +++ b/vite.config.js @@ -1,7 +1,8 @@ import { defineConfig } from 'vite'; import path from 'path'; -// eslint-disable-next-line import/no-extraneous-dependencies import dts from 'vite-plugin-dts'; +import { nodePolyfills } from 'vite-plugin-node-polyfills'; + // https://vitejs.dev/config/ export default defineConfig({ // @ts-ignore @@ -9,20 +10,30 @@ export default defineConfig({ test: { globals: true, }, + resolve: { alias: { '~': `${path.resolve(__dirname, 'src')}`, }, }, + build: { manifest: true, minify: true, reportCompressedSize: true, lib: { entry: path.resolve(__dirname, 'src/index.ts'), - name: 'index', - formats: ['es', 'cjs'], + name: 'shadejs', + fileName: 'index', }, }, - plugins: [dts({ rollupTypes: true })], + plugins: [ + dts({ rollupTypes: true }), + nodePolyfills({ + include: ['path', 'buffer'], + globals: { + Buffer: true, + }, + }), + ], }); diff --git a/vite.config.ts b/vite.config.ts deleted file mode 100644 index 54fe29d..0000000 --- a/vite.config.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { defineConfig } from 'vite'; -import path from 'path'; -// eslint-disable-next-line import/no-extraneous-dependencies -import dts from 'vite-plugin-dts'; -// eslint-disable-next-line import/no-extraneous-dependencies -import { nodePolyfills } from 'vite-plugin-node-polyfills'; - -// https://vitejs.dev/config/ -export default defineConfig({ - - // @ts-ignore - // vitest configs - test: { - globals: true, - }, - - resolve: { - alias: { - '~': `${path.resolve(__dirname, 'src')}`, - }, - }, - - build: { - target: 'node', - manifest: true, - minify: true, - reportCompressedSize: true, - lib: { - entry: path.resolve(__dirname, 'src/index.ts'), - name: 'ShadeJS', - fileName: 'shade-js', - }, - }, - plugins: [ - dts({ rollupTypes: true }), - nodePolyfills({ - include: ['path'], - }), - ], -});