Skip to content

Commit

Permalink
Use Buffer polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev committed Dec 19, 2024
1 parent c10b46e commit 819f0c5
Show file tree
Hide file tree
Showing 4 changed files with 483 additions and 5 deletions.
16 changes: 15 additions & 1 deletion packages/keychain/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { StorybookConfig } from "@storybook/react-vite";
import { join, dirname } from "path";
import { mergeConfig } from "vite";

/**
* This function is used to resolve the absolute path of a package.
Expand All @@ -19,7 +20,20 @@ const config: StorybookConfig = {
],
framework: {
name: getAbsolutePath("@storybook/react-vite"),
options: {},
options: {
builder: {
viteConfigPath: "./vite.config.ts",
},
},
},
viteFinal: async (config) => {
return mergeConfig(config, {
build: {
rollupOptions: {
external: ["vite-plugin-node-polyfills/shims/global"],
},
},
});
},
staticDirs: ["../public"],
};
Expand Down
1 change: 1 addition & 0 deletions packages/keychain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"tailwindcss": "^3.4.3",
"typescript": "^5.4.5",
"vite": "^6.0.3",
"vite-plugin-node-polyfills": "^0.22.0",
"vite-plugin-top-level-await": "^1.4.4",
"vite-plugin-wasm": "^3.3.0",
"vitest": "^2.1.8",
Expand Down
18 changes: 17 additions & 1 deletion packages/keychain/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@ import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import wasm from "vite-plugin-wasm";
import topLevelAwait from "vite-plugin-top-level-await";
import { nodePolyfills } from "vite-plugin-node-polyfills";

export default defineConfig(({ mode }) => ({
plugins: [wasm(), topLevelAwait(), react()],
plugins: [
nodePolyfills({
include: ["buffer"],
globals: {
Buffer: true,
},
}),
wasm(),
topLevelAwait(),
react(),
],
server: {
port: mode === "development" ? 3001 : undefined,
},
Expand All @@ -15,4 +26,9 @@ export default defineConfig(({ mode }) => ({
},
root: "./",
publicDir: "public",
build: {
rollupOptions: {
external: ["vite-plugin-node-polyfills/shims/global"],
},
},
}));
Loading

0 comments on commit 819f0c5

Please sign in to comment.