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

Commit 4ee3cf3

Browse files
authored
4x webpack build config (#5111)
* webpack required pckages and script * initial webpack build config * libs install changes yarnlock * webpack clean dist * webpack build * allow dist dir at root * initial test build * webpack build config * dnt commit build * remove build * web3 min
1 parent d5dc395 commit 4ee3cf3

File tree

3 files changed

+381
-37
lines changed

3 files changed

+381
-37
lines changed

package.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
]
3333
},
3434
"scripts": {
35-
"build": "yarn clean && lerna run build --stream",
35+
"build": "yarn clean && lerna run build --stream && webpack --config webpackprod.config.js",
3636
"clean": "lerna run clean --stream --parallel",
3737
"ganache:start": "WEB3_SYSTEM_TEST_BACKEND=ganache && ./scripts/ganache.sh start",
3838
"ganache:start:background": "WEB3_SYSTEM_TEST_BACKEND=ganache && ./scripts/ganache.sh start 1",
@@ -59,14 +59,18 @@
5959
},
6060
"devDependencies": {
6161
"@cypress/webpack-preprocessor": "^5.11.1",
62+
"@droppedcode/typedoc-plugin-relative-includes": "^1.0.2",
6263
"@openzeppelin/contracts": "^4.6.0",
63-
"@types/node": "*",
64+
"@types/node": "^17.0.40",
65+
"@types/webpack": "^5.28.0",
6466
"assert": "^2.0.0",
6567
"buffer": "^6.0.3",
6668
"bufferutil": "^4.0.6",
69+
"clean-webpack-plugin": "^4.0.0",
6770
"crypto-browserify": "^3.12.0",
6871
"cypress": "^9.6.0",
6972
"cypress-jest-adapter": "^0.1.1",
73+
"declaration-bundler-webpack-plugin": "^1.0.3",
7074
"eslint": "^8.3.0",
7175
"http-browserify": "^1.7.0",
7276
"https-browserify": "^1.0.0",
@@ -79,17 +83,17 @@
7983
"process": "^0.11.10",
8084
"solc": "^0.8.13",
8185
"ts-jest": "^27.0.7",
82-
"ts-loader": "^9.2.8",
86+
"ts-loader": "^9.3.0",
8387
"ts-node": "^10.4.0",
84-
"typescript": "^4.5.2",
8588
"typedoc": "^0.22.15",
86-
"typedoc-plugin-markdown": "^3.12.1",
8789
"typedoc-monorepo-link-types": "^0.0.2",
8890
"typedoc-plugin-extras": "^2.2.3",
89-
"@droppedcode/typedoc-plugin-relative-includes": "^1.0.2",
91+
"typedoc-plugin-markdown": "^3.12.1",
9092
"typedoc-plugin-mdn-links": "^1.0.6",
93+
"typescript": "^4.5.2",
9194
"utf-8-validate": "^5.0.9",
92-
"webpack": "^5.72.0"
95+
"webpack": "^5.73.0",
96+
"webpack-cli": "^4.9.2"
9397
},
9498
"packageManager": "[email protected]"
9599
}

webpackprod.config.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const webpack = require('webpack');
2+
const path = require('path');
3+
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
4+
5+
const config = {
6+
mode: 'production',
7+
entry: path.resolve(__dirname, 'packages/web3/src/index.ts'),
8+
output: {
9+
path: path.resolve(__dirname, 'dist'),
10+
filename: 'web3.min.js',
11+
library: 'Web3',
12+
libraryExport: 'default',
13+
libraryTarget: 'umd',
14+
globalObject: 'this',
15+
},
16+
17+
module: {
18+
rules: [
19+
{
20+
test: /\.ts$/,
21+
loader: 'ts-loader',
22+
exclude: ['/node_modules/', '/unit/'],
23+
},
24+
],
25+
},
26+
resolve: {
27+
extensions: ['.ts', '.js'],
28+
fallback: {
29+
child_process: false,
30+
fs: false,
31+
net: false,
32+
path: false,
33+
os: false,
34+
util: require.resolve('util'),
35+
http: require.resolve('http-browserify'),
36+
https: require.resolve('https-browserify'),
37+
crypto: require.resolve('crypto-browserify'),
38+
stream: require.resolve('readable-stream'),
39+
},
40+
alias: {
41+
// To avoid blotting up the `bn.js` library all over the packages
42+
// use single library instance.
43+
'bn.js': path.resolve(__dirname, 'node_modules/bn.js'),
44+
},
45+
},
46+
devtool: 'source-map',
47+
plugins: [
48+
new CleanWebpackPlugin({
49+
verbose: true,
50+
}),
51+
new webpack.IgnorePlugin({
52+
checkResource(resource) {
53+
// "@ethereumjs/common/genesisStates" consists ~800KB static files which are no more needed
54+
return /(.*\/genesisStates\/.*\.json)/.test(resource);
55+
},
56+
}),
57+
new webpack.ProvidePlugin({
58+
Buffer: ['buffer', 'Buffer'],
59+
}),
60+
new webpack.ProvidePlugin({
61+
process: 'process/browser',
62+
}),
63+
],
64+
};
65+
66+
module.exports = () => {
67+
return config;
68+
};

0 commit comments

Comments
 (0)