Skip to content
This repository was archived by the owner on Oct 12, 2025. It is now read-only.

Commit cf96418

Browse files
committed
update vite configs
1 parent 18c1420 commit cf96418

File tree

5 files changed

+62
-33
lines changed

5 files changed

+62
-33
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"dev": "turbo run dev",
77
"lint": "turbo run lint",
88
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
9-
"check-types": "turbo run check-types"
9+
"check-types": "turbo run check-types",
10+
"dev:snap": "turbo run dev --filter=@ecency/snap",
11+
"dev:playground": "turbo run dev --filter=@ecency/snap-playground",
12+
"dev:extras": "run-p dev:snap dev:playground"
1013
},
1114
"devDependencies": {
1215
"prettier": "^3.5.3",

packages/snap-playground/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"version": "0.1.0",
55
"type": "module",
66
"scripts": {
7-
"start": "yarn workspace @ecency/snap build && vite",
7+
"dev": "yarn workspace @ecency/snap dev & vite --port 5173 --strictPort",
8+
"start": "yarn workspace @ecency/snap build && vite preview --port 5173 --strictPort",
89
"build": "yarn workspace @ecency/snap build && vite build"
910
},
1011
"devDependencies": {

packages/snap/package.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@
44
"version": "0.1.0",
55
"type": "module",
66
"license": "MIT",
7-
"main": "./dist/index.js",
8-
"typings": "./dist/index.d.ts",
9-
"files": [
10-
"dist",
11-
"README.md"
12-
],
7+
"main": "dist/bundle.js",
8+
"types": "dist/index.d.ts",
9+
"files": ["dist", "snap.manifest.json", "README.md"],
1310
"scripts": {
14-
"dev": "vite",
15-
"build": "tsc && vite build && node build-manifest.cjs",
11+
"dev": "vite build --watch",
12+
"build": "vite build",
1613
"test": "NODE_OPTIONS=--import=./test/mock-wallets.js node --test"
1714
},
1815
"dependencies": {

packages/snap/snap.manifest.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
"source": {
66
"shasum": "+gn3cFrS+R+J+5IBVFADiePNDRkejucH5jyiRiIEnf4=",
77
"location": {
8-
"npm": {
9-
"filePath": "dist/bundle.js",
10-
"packageName": "@ecency/snap",
11-
"registry": "https://registry.npmjs.org"
8+
"http": {
9+
"url": "http://localhost:5173/dist/bundle.js"
1210
}
1311
}
1412
},
@@ -25,4 +23,4 @@
2523
"endowment:webassembly": {}
2624
},
2725
"manifestVersion": "0.1"
28-
}
26+
}

packages/snap/vite.config.ts

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,67 @@
11
import path from "path";
2+
import fs from "fs";
3+
import { createHash } from "crypto";
24
import { defineConfig } from "vite";
5+
import type { Plugin } from "vite";
36
import dtsPlugin from "vite-plugin-dts";
4-
import { nodePolyfills } from "vite-plugin-node-polyfills";
7+
// Polyfills are usually not needed in the snap runtime. Keep it only if you know you need specific shims.
8+
// import { nodePolyfills } from "vite-plugin-node-polyfills";
9+
10+
function updateManifestShasum(): Plugin {
11+
return {
12+
name: "update-manifest-shasum",
13+
closeBundle() {
14+
const bundlePath = path.resolve(__dirname, "dist", "bundle.js");
15+
if (!fs.existsSync(bundlePath)) return;
16+
17+
const source = fs.readFileSync(bundlePath);
18+
const shasum = createHash("sha256").update(source).digest("base64"); // MetaMask expects base64 sha256
19+
20+
const manifestPath = path.resolve(__dirname, "snap.manifest.json");
21+
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
22+
23+
// IMPORTANT: this URL must match how the file will be fetched by MetaMask
24+
// Your playground serves ../snap at http://localhost:5173/
25+
manifest.source = manifest.source ?? {};
26+
manifest.source.location = manifest.source.location ?? {};
27+
manifest.source.location.http = {
28+
url: "http://localhost:5173/dist/bundle.js",
29+
};
30+
manifest.source.shasum = shasum;
31+
32+
fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
33+
console.log("[snap] Updated manifest shasum");
34+
},
35+
};
36+
}
537

638
export default defineConfig({
739
build: {
40+
target: "es2020",
41+
sourcemap: false,
42+
minify: "esbuild",
43+
emptyOutDir: true,
844
lib: {
945
entry: path.resolve(__dirname, "src/index.ts"),
10-
name: "Ecency Snap",
11-
formats: ["es"],
46+
name: "EcencySnap",
47+
formats: ["iife"], // self-executing, no imports
1248
fileName: () => "bundle.js",
1349
},
1450
rollupOptions: {
15-
external: [
16-
"crypto",
17-
"@ecency/wallets",
18-
"@okxweb3/coin-aptos",
19-
"@okxweb3/coin-base",
20-
"@okxweb3/coin-bitcoin",
21-
"@okxweb3/coin-cosmos",
22-
"@okxweb3/coin-ethereum",
23-
"@okxweb3/coin-solana",
24-
"@okxweb3/coin-ton",
25-
"@okxweb3/coin-tron",
26-
"@okxweb3/crypto-lib",
27-
"bip39",
28-
],
51+
output: {
52+
inlineDynamicImports: true, // single file
53+
},
54+
treeshake: true,
2955
},
3056
},
3157
resolve: {
3258
alias: {
3359
"@": path.resolve(__dirname, "./src"),
3460
},
3561
},
36-
plugins: [dtsPlugin(), nodePolyfills()],
62+
plugins: [
63+
dtsPlugin({ insertTypesEntry: false }),
64+
// nodePolyfills(),
65+
updateManifestShasum(),
66+
],
3767
});

0 commit comments

Comments
 (0)