Skip to content

Commit

Permalink
Merge pull request #282 from suiet/feat/refactor-bundling
Browse files Browse the repository at this point in the history
Feat/refactor bundling
  • Loading branch information
bruceeewong authored Nov 15, 2023
2 parents eab2408 + e26db71 commit 7c64cab
Show file tree
Hide file tree
Showing 7 changed files with 1,537 additions and 313 deletions.
4 changes: 3 additions & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"postcss": "^8.4.19",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rollup-plugin-visualizer": "^5.9.2",
"sass": "^1.56.1",
"semantic-release": "^19.0.5",
"ts-jest": "^28.0.8",
Expand All @@ -65,7 +66,8 @@
},
"peerDependencies": {
"@mysten/sui.js": "0.45.1",
"@mysten/wallet-standard": "0.8.7"
"react": "*",
"react-dom": "*"
},
"repository": {
"type": "git",
Expand Down
85 changes: 56 additions & 29 deletions packages/kit/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,72 @@
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
import viteSvgr from 'vite-plugin-svgr';
import path from 'path';
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
import viteSvgr from "vite-plugin-svgr";
import path from "path";
import { visualizer } from "rollup-plugin-visualizer";

// https://vitejs.dev/config/
export default defineConfig(({mode}) => ({
plugins: [react(), vanillaExtractPlugin(), viteSvgr()],
css: {
modules: {
localsConvention: 'camelCase',
},
},
esbuild: {
target: "es2020",
pure: mode === 'production' ? ['console.log', 'debugger'] : [],
},
optimizeDeps: {
esbuildOptions : {
target: "es2020"
}
},
export default defineConfig(({ mode }) => ({
build: {
target: 'es2020',
target: "es2020",
lib: {
entry: path.resolve(__dirname, './src/index.ts'),
fileName: 'index',
name: 'suietWalletKit'
entry: path.resolve(__dirname, "./src/index.ts"),
fileName: "index",
name: "suietWalletKit",
},
emptyOutDir: false,
sourcemap: false,
minify: true,
rollupOptions: {
external: ['react', 'react-dom', '@mysten/sui.js'],
external: [
"react",
"react-dom",
"react/jsx-runtime",
"@mysten/sui.js",
"@mysten/sui.js/client",
"@mysten/sui.js/bcs",
"@mysten/sui.js/utils",
"@mysten/sui.js/verify",
"@mysten/sui.js/transactions",
],
output: {
// Provide global variables to use in the UMD build
// for externalized deps.
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'@mysten/sui.js': 'Sui'
react: "React",
"react-dom": "ReactDOM",
"react/jsx-runtime": "react/jsx-runtime",
"@mysten/sui.js": "Sui",
"@mysten/sui.js/client": "Sui",
"@mysten/sui.js/bcs": "Sui",
"@mysten/sui.js/utils": "Sui",
"@mysten/sui.js/verify": "Sui",
"@mysten/sui.js/transactions": "Sui",
},
},
},
},
css: {
modules: {
localsConvention: "camelCase",
},
},
esbuild: {
target: "es2020",
pure: mode === "production" ? ["console.log", "debugger"] : [],
},
optimizeDeps: {
esbuildOptions: {
target: "es2020",
},
},
plugins: [
react(),
vanillaExtractPlugin(),
viteSvgr(),
visualizer({
open: false, // This opens the visualization in your browser after the build
filename: "bundle-analysis.html", // The output file for the report
}),
],
}));
3 changes: 2 additions & 1 deletion packages/sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
coverage/
coverage/
bundle-analysis.html
4 changes: 2 additions & 2 deletions packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
"jest-environment-jsdom": "^28.1.3",
"jest-simple-dot-reporter": "^1.0.5",
"rimraf": "^3.0.2",
"rollup-plugin-visualizer": "^5.9.2",
"ts-jest": "^28.0.8",
"ts-node": "^10.9.1",
"typescript": "^5.1.6",
"vite": "^3.2.7",
"vite-plugin-dts": "^2.3.0"
},
"peerDependencies": {
"@mysten/sui.js": "0.45.1",
"@mysten/wallet-standard": "0.8.7"
"@mysten/sui.js": "0.45.1"
}
}
3 changes: 1 addition & 2 deletions packages/sdk/src/account/AccountCoinManager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { IAccountCoinManager } from "./interfaces";
import { CoinObject } from "../common";
import { SuiClient } from "@mysten/sui.js/client";
import { SuiClient, PaginatedCoins } from "@mysten/sui.js/client";
import { AccountObjectManager } from "./AccountObjectManager";
import { PaginatedCoins } from "@mysten/sui.js/src/client/types";

export class AccountCoinManager
extends AccountObjectManager
Expand Down
42 changes: 21 additions & 21 deletions packages/sdk/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@
import { resolve } from "path";
import { defineConfig } from "vite";
import dts from "vite-plugin-dts";
import inject from "@rollup/plugin-inject";
import { visualizer } from "rollup-plugin-visualizer";

export default defineConfig(({ mode }) => ({
build: {
target: "es2020",
commonjsOptions: {
// vite build use @rollup/plugin-commonjs as default, which transforms all the cjs files
// However Sui Sdk mixed using esm & cjs,therefore should turn on transformMixedEsModules.
// https://github.com/originjs/vite-plugins/issues/9#issuecomment-924668456
transformMixedEsModules: true,
},
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(__dirname, "src/index.ts"),
name: "suietWalletSdk",
// the proper extensions will be added
fileName: "index",
},
sourcemap: false,
minify: true,
esbuild: {
target: "es2020",
pure: mode === "production" ? ["console.log", "debugger"] : [],
},
optimizeDeps: {
esbuildOptions: {
target: "es2020",
define: {
global: "globalThis",
},
},
},
rollupOptions: {
// make sure to externalize deps that shouldn't be bundled
// into your library
external: ["@mysten/sui.js"],
external: [
"@mysten/sui.js",
"@mysten/sui.js/client",
"@mysten/sui.js/bcs",
"@mysten/sui.js/utils",
"@mysten/sui.js/verify",
],
output: {
// Provide global variables to use in the UMD build
// for externalized deps
globals: {
"@mysten/sui.js": "Sui",
"@mysten/sui.js/client": "Sui",
"@mysten/sui.js/bcs": "Sui",
"@mysten/sui.js/utils": "Sui",
"@mysten/sui.js/verify": "Sui",
},
},
plugins: [inject({ Buffer: ["buffer", "Buffer"] })],
},
},
plugins: [dts()],
plugins: [
dts(),
visualizer({
open: false, // This opens the visualization in your browser after the build
filename: "bundle-analysis.html", // The output file for the report
}),
],
}));
Loading

2 comments on commit 7c64cab

@vercel
Copy link

@vercel vercel bot commented on 7c64cab Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

wallet-kit-with-nextjs-app-router – ./examples/with-next-app-router

wallet-kit-with-nextjs-app-router-suiet.vercel.app
wallet-kit-with-nextjs-app-router.vercel.app
wallet-kit-with-nextjs-app-router-git-main-suiet.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 7c64cab Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

wallet-kit-demo – ./examples/with-vite

wallet-kit-demo.vercel.app
wallet-kit-demo-git-main-suiet.vercel.app
wallet-kit-demo-suiet.vercel.app

Please sign in to comment.