This repository has been archived by the owner on Jun 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
128 lines (118 loc) · 3.51 KB
/
webpack.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// shared config (dev and prod)
const path = require("path");
const webpack = require("webpack");
const nodeExternals = require('webpack-node-externals');
const basicConfig = {
context: path.resolve(__dirname, "./src"),
entry: "./index.ts",
target: 'node',
mode: "production",
output: {
filename: "index.js",
path: path.resolve(__dirname, "./lib"),
libraryTarget: 'umd',
library: 'PolyjuiceHttpProvider',
libraryExport: 'default',
globalObject: 'this',
},
// in order to ignore all modules in node_modules folder
externals: [nodeExternals()],
resolve: {
extensions: [".js", ".ts"],
fallback: {
stream: require.resolve("stream-browserify"),
http: require.resolve("stream-http"),
https: require.resolve("https-browserify"),
url: require.resolve("url"),
os: require.resolve("os-browserify/browser"),
crypto: require.resolve("crypto-browserify")
},
alias: {
"./godwoken": path.resolve(__dirname, "src/godwoken"),
buffer: path.join(__dirname, "./node_modules/buffer"),
Buffer: path.join(__dirname, "./node_modules/buffer"),
process: "process/browser",
"@ethersproject/wallet/src.ts/_version": path.join(__dirname, "./node_modules/@ethersproject/wallet/src.ts/_version"),
},
},
module: {
rules: [
{
test: [/\.js?$/, /\.ts?$/],
use: ["ts-loader"],
exclude: /node_modules/,
},
],
},
plugins: [
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
new webpack.ProvidePlugin({
process: "process/browser",
}),
new webpack.ProvidePlugin({
transformruntime: "process/browser",
}),
new webpack.ProvidePlugin({
fetch: "cross-fetch",
}),
],
optimization: {
minimize: false,
},
};
// ========= web3.js compatibale provider =========
// can be used in web dev such as react
const clientConfig = {...basicConfig, ...{
target: 'web',
output: {...basicConfig.output, ...{
filename: 'index.js',
}}
}};
// can be used in nodejs env for sign_message_with_private_key
const cliConfig = {...basicConfig, ...{
target: 'node',
entry: "./cli.ts",
output: {...basicConfig.output, ...{
filename: 'cli.js',
}}
}};
// can be used by html script tag. eg: <script src="/path/to/PolyjuiceHttpProvider.js"></script>
const browserConfig = {...basicConfig, ...{
target: 'web',
output: {...basicConfig.output, ...{
path: path.resolve(__dirname, "./build/browser/"),
filename: 'PolyjuiceHttpProvider.js',
}},
externals: [],
}}
//======== ethers compatibale provider and signer ===========
// can be used in hardhat
const ethersProvidersConfig = {...basicConfig, ...{
target: 'web',
context: path.resolve(__dirname, "./src/hardhat"),
entry: "./providers.ts",
output: {...basicConfig.output, ...{
path: path.resolve(__dirname, "./lib/hardhat/"),
filename: 'providers.js',
libraryTarget: 'umd',
library: 'PolyjuiceProviders',
libraryExport: 'default',
globalObject: 'this',
}}
}}
const ethersWalletSignerConfig = {...basicConfig, ...{
target: 'web',
context: path.resolve(__dirname, "./src/hardhat"),
entry: "./wallet-signer.ts",
output: {...basicConfig.output, ...{
path: path.resolve(__dirname, "./lib/hardhat/"),
filename: 'wallet-signer.js',
libraryTarget: 'umd',
library: 'PolyjuiceWalletSigner',
libraryExport: 'default',
globalObject: 'this',
}}
}}
module.exports = [clientConfig, browserConfig, cliConfig, ethersProvidersConfig, ethersWalletSignerConfig];