-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.js
53 lines (52 loc) · 1.72 KB
/
vite.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// vite.config.js
import fs from "fs";
import path from "path";
import { defineConfig } from "vite";
import dts from "vite-plugin-dts";
import packageJson from "./package.json";
// import inject from "@rollup/plugin-inject";
export default defineConfig({
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
entry: path.resolve(__dirname, "src/index.ts"),
name: "HardwareWalletConnection",
// the proper extensions will be added
fileName: "index",
},
outDir: "lib",
},
plugins: [
dts({
exclude: ["events"],
clearPureImport: true,
rollupTypes: true,
bundledPackages: [
"@ethersproject/bignumber",
"@ethersproject/transactions",
"@ledgerhq/devices",
"@ledgerhq/domain-service",
"@ledgerhq/hw-app-eth",
"@ledgerhq/hw-transport",
"@ledgerhq/hw-transport-webusb",
"@ledgerhq/types-live",
"ethers",
],
afterBuild: async () => {
/**
* vite-plugin-dts does an awesome job of inlining declarations
* of the dependencies, but has a weird bug of including just one
* incorrect import. Here we absolutely inelegantly fix this bug
* by replacing the import with an unknown type
*/
const filePath = packageJson.types;
const filePathAbs = path.join(__dirname, filePath);
const content = fs.readFileSync(filePathAbs, "utf-8");
const searchValue = "import { EIP712Message } from './modules/EIP712';";
const replaceValue = "type EIP712Message = unknown;";
const replaced = content.replace(searchValue, replaceValue);
fs.writeFileSync(filePath, replaced);
},
}),
],
});