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

Commit 2992fe9

Browse files
nazarhussainjdevcsavkos
authored
🎨 Update the webpack to build per package (#5140)
* 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 * 🎨 Update the webpack to build per package * 🙈 Ignore the webpack config from linting * 💚 Update web build step to CI * 🎨 Merge the build tasks * 🚨 Fix lint error Co-authored-by: jdevcs <[email protected]> Co-authored-by: Junaid <[email protected]> Co-authored-by: Oleksii Kosynskyi <[email protected]>
1 parent 8c3e931 commit 2992fe9

File tree

10 files changed

+137
-70
lines changed

10 files changed

+137
-70
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ jobs:
2121
node-version: 14
2222
cache: yarn
2323
- run: yarn
24-
24+
- run: yarn build:web
25+
2526
lint:
2627
name: lint
2728
needs: build

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
]
3333
},
3434
"scripts": {
35-
"build": "yarn clean && lerna run build --stream && webpack --config webpackprod.config.js",
35+
"prebuild": "yarn clean",
36+
"build": "lerna run build --stream",
37+
"build:web": "lerna run build:web --stream",
3638
"clean": "lerna run clean --stream --parallel",
3739
"ganache:start": "WEB3_SYSTEM_TEST_BACKEND=ganache && ./scripts/ganache.sh start",
3840
"ganache:start:background": "WEB3_SYSTEM_TEST_BACKEND=ganache && ./scripts/ganache.sh start 1",

packages/web3-validator/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
dist
22
jest.config.js
33
.eslintrc.js
4+
webpack.config.js

packages/web3-validator/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.1.0-alpha.0",
44
"description": "JSON-Schema compatible validator for web3",
55
"main": "dist/index.js",
6+
"browser": "dist/index.min.js",
67
"repository": "https://github.com/ChainSafe/web3.js",
78
"author": "ChainSafe Systems",
89
"license": "LGPL-3.0",
@@ -13,6 +14,7 @@
1314
"clean": "rimraf dist",
1415
"prebuild": "rimraf dist",
1516
"build": "tsc --build",
17+
"build:web": "npx webpack",
1618
"build:check": "node -e \"require('./dist')\"",
1719
"lint": "eslint --ext .js,.ts .",
1820
"lint:fix": "eslint --fix --ext .js,.ts .",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
This file is part of web3.js.
3+
4+
web3.js is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU Lesser General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
web3.js is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public License
15+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
const { getWebPackConfig } = require('../../webpack.base.config');
19+
20+
module.exports = getWebPackConfig(__dirname, 'index.min.js', 'web3-validator');

packages/web3/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
dist
22
jest.config.js
3+
webpack.config.js
34
.eslintrc.js

packages/web3/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "4.0.0-alpha.1",
44
"description": "Ethereum JavaScript API",
55
"main": "dist/index.js",
6+
"browser": "dist/web3.min.js",
67
"repository": "https://github.com/ChainSafe/web3.js",
78
"engines": {
89
"node": ">=12.0.0"
@@ -21,6 +22,7 @@
2122
"clean": "rimraf dist",
2223
"prebuild": "rimraf dist",
2324
"build": "tsc --build",
25+
"build:web": "npx webpack",
2426
"build:check": "node -e \"require('./dist')\"",
2527
"lint": "eslint --ext .js,.ts .",
2628
"lint:fix": "eslint --fix --ext .js,.ts .",

packages/web3/webpack.config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
This file is part of web3.js.
3+
4+
web3.js is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU Lesser General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
web3.js is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public License
15+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
const { getWebPackConfig } = require('../../webpack.base.config');
19+
20+
module.exports = getWebPackConfig(__dirname, 'web3.min.js', 'Web3');

webpack.base.config.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
This file is part of web3.js.
3+
4+
web3.js is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU Lesser General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
web3.js is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public License
15+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
const webpack = require('webpack');
19+
const path = require('path');
20+
21+
/**
22+
* Shared webpack configuration for all packages
23+
*/
24+
function getWebPackConfig(packagePath, filename, library) {
25+
return {
26+
mode: 'production',
27+
entry: path.resolve(packagePath, 'src/index.ts'),
28+
output: {
29+
path: path.resolve(packagePath, 'dist'),
30+
filename: filename,
31+
library: library,
32+
libraryExport: 'default',
33+
libraryTarget: 'umd',
34+
globalObject: 'this',
35+
},
36+
37+
module: {
38+
rules: [
39+
{
40+
test: /\.ts$/,
41+
loader: 'ts-loader',
42+
exclude: ['/node_modules/', '/test/'],
43+
},
44+
],
45+
},
46+
resolve: {
47+
extensions: ['.ts', '.js'],
48+
fallback: {
49+
child_process: false,
50+
fs: false,
51+
net: false,
52+
path: false,
53+
os: false,
54+
util: require.resolve('util'),
55+
http: require.resolve('http-browserify'),
56+
https: require.resolve('https-browserify'),
57+
crypto: require.resolve('crypto-browserify'),
58+
stream: require.resolve('readable-stream'),
59+
},
60+
alias: {
61+
// To avoid blotting up the `bn.js` library all over the packages
62+
// use single library instance.
63+
'bn.js': path.resolve(__dirname, 'node_modules/bn.js'),
64+
},
65+
},
66+
devtool: 'source-map',
67+
plugins: [
68+
new webpack.IgnorePlugin({
69+
checkResource(resource) {
70+
// "@ethereumjs/common/genesisStates" consists ~800KB static files which are no more needed
71+
return /(.*\/genesisStates\/.*\.json)/.test(resource);
72+
},
73+
}),
74+
new webpack.ProvidePlugin({
75+
Buffer: ['buffer', 'Buffer'],
76+
}),
77+
new webpack.ProvidePlugin({
78+
process: 'process/browser',
79+
}),
80+
],
81+
};
82+
}
83+
84+
module.exports = {
85+
getWebPackConfig,
86+
};

webpackprod.config.js

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)