diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d9106daa4e7..5f34a505adc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -21,7 +21,8 @@ jobs: node-version: 14 cache: yarn - run: yarn - + - run: yarn build:web + lint: name: lint needs: build diff --git a/package.json b/package.json index d84cee5c0b2..1cd686e0ac5 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,9 @@ ] }, "scripts": { - "build": "yarn clean && lerna run build --stream && webpack --config webpackprod.config.js", + "prebuild": "yarn clean", + "build": "lerna run build --stream", + "build:web": "lerna run build:web --stream", "clean": "lerna run clean --stream --parallel", "ganache:start": "WEB3_SYSTEM_TEST_BACKEND=ganache && ./scripts/ganache.sh start", "ganache:start:background": "WEB3_SYSTEM_TEST_BACKEND=ganache && ./scripts/ganache.sh start 1", diff --git a/packages/web3-validator/.eslintignore b/packages/web3-validator/.eslintignore index 61692fa813f..0204aab9ff1 100644 --- a/packages/web3-validator/.eslintignore +++ b/packages/web3-validator/.eslintignore @@ -1,3 +1,4 @@ dist jest.config.js .eslintrc.js +webpack.config.js \ No newline at end of file diff --git a/packages/web3-validator/package.json b/packages/web3-validator/package.json index a3edb63dfbc..f1758ed9220 100644 --- a/packages/web3-validator/package.json +++ b/packages/web3-validator/package.json @@ -3,6 +3,7 @@ "version": "0.1.0-alpha.0", "description": "JSON-Schema compatible validator for web3", "main": "dist/index.js", + "browser": "dist/index.min.js", "repository": "https://github.com/ChainSafe/web3.js", "author": "ChainSafe Systems", "license": "LGPL-3.0", @@ -13,6 +14,7 @@ "clean": "rimraf dist", "prebuild": "rimraf dist", "build": "tsc --build", + "build:web": "npx webpack", "build:check": "node -e \"require('./dist')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/packages/web3-validator/webpack.config.js b/packages/web3-validator/webpack.config.js new file mode 100644 index 00000000000..dadcbb550a6 --- /dev/null +++ b/packages/web3-validator/webpack.config.js @@ -0,0 +1,20 @@ +/* +This file is part of web3.js. + +web3.js is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +web3.js is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with web3.js. If not, see . +*/ + +const { getWebPackConfig } = require('../../webpack.base.config'); + +module.exports = getWebPackConfig(__dirname, 'index.min.js', 'web3-validator'); diff --git a/packages/web3/.eslintignore b/packages/web3/.eslintignore index 61692fa813f..7601e9c18b5 100644 --- a/packages/web3/.eslintignore +++ b/packages/web3/.eslintignore @@ -1,3 +1,4 @@ dist jest.config.js +webpack.config.js .eslintrc.js diff --git a/packages/web3/package.json b/packages/web3/package.json index ced7ea6fc4c..c8479773351 100644 --- a/packages/web3/package.json +++ b/packages/web3/package.json @@ -3,6 +3,7 @@ "version": "4.0.0-alpha.1", "description": "Ethereum JavaScript API", "main": "dist/index.js", + "browser": "dist/web3.min.js", "repository": "https://github.com/ChainSafe/web3.js", "engines": { "node": ">=12.0.0" @@ -21,6 +22,7 @@ "clean": "rimraf dist", "prebuild": "rimraf dist", "build": "tsc --build", + "build:web": "npx webpack", "build:check": "node -e \"require('./dist')\"", "lint": "eslint --ext .js,.ts .", "lint:fix": "eslint --fix --ext .js,.ts .", diff --git a/packages/web3/webpack.config.js b/packages/web3/webpack.config.js new file mode 100644 index 00000000000..57b19a48193 --- /dev/null +++ b/packages/web3/webpack.config.js @@ -0,0 +1,20 @@ +/* +This file is part of web3.js. + +web3.js is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +web3.js is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with web3.js. If not, see . +*/ + +const { getWebPackConfig } = require('../../webpack.base.config'); + +module.exports = getWebPackConfig(__dirname, 'web3.min.js', 'Web3'); diff --git a/webpack.base.config.js b/webpack.base.config.js new file mode 100644 index 00000000000..9a9483f7d4d --- /dev/null +++ b/webpack.base.config.js @@ -0,0 +1,86 @@ +/* +This file is part of web3.js. + +web3.js is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +web3.js is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with web3.js. If not, see . +*/ + +const webpack = require('webpack'); +const path = require('path'); + +/** + * Shared webpack configuration for all packages + */ +function getWebPackConfig(packagePath, filename, library) { + return { + mode: 'production', + entry: path.resolve(packagePath, 'src/index.ts'), + output: { + path: path.resolve(packagePath, 'dist'), + filename: filename, + library: library, + libraryExport: 'default', + libraryTarget: 'umd', + globalObject: 'this', + }, + + module: { + rules: [ + { + test: /\.ts$/, + loader: 'ts-loader', + exclude: ['/node_modules/', '/test/'], + }, + ], + }, + resolve: { + extensions: ['.ts', '.js'], + fallback: { + child_process: false, + fs: false, + net: false, + path: false, + os: false, + util: require.resolve('util'), + http: require.resolve('http-browserify'), + https: require.resolve('https-browserify'), + crypto: require.resolve('crypto-browserify'), + stream: require.resolve('readable-stream'), + }, + alias: { + // To avoid blotting up the `bn.js` library all over the packages + // use single library instance. + 'bn.js': path.resolve(__dirname, 'node_modules/bn.js'), + }, + }, + devtool: 'source-map', + plugins: [ + new webpack.IgnorePlugin({ + checkResource(resource) { + // "@ethereumjs/common/genesisStates" consists ~800KB static files which are no more needed + return /(.*\/genesisStates\/.*\.json)/.test(resource); + }, + }), + new webpack.ProvidePlugin({ + Buffer: ['buffer', 'Buffer'], + }), + new webpack.ProvidePlugin({ + process: 'process/browser', + }), + ], + }; +} + +module.exports = { + getWebPackConfig, +}; diff --git a/webpackprod.config.js b/webpackprod.config.js deleted file mode 100644 index d9454d2996a..00000000000 --- a/webpackprod.config.js +++ /dev/null @@ -1,68 +0,0 @@ -const webpack = require('webpack'); -const path = require('path'); -const { CleanWebpackPlugin } = require('clean-webpack-plugin'); - -const config = { - mode: 'production', - entry: path.resolve(__dirname, 'packages/web3/src/index.ts'), - output: { - path: path.resolve(__dirname, 'dist'), - filename: 'web3.min.js', - library: 'Web3', - libraryExport: 'default', - libraryTarget: 'umd', - globalObject: 'this', - }, - - module: { - rules: [ - { - test: /\.ts$/, - loader: 'ts-loader', - exclude: ['/node_modules/', '/unit/'], - }, - ], - }, - resolve: { - extensions: ['.ts', '.js'], - fallback: { - child_process: false, - fs: false, - net: false, - path: false, - os: false, - util: require.resolve('util'), - http: require.resolve('http-browserify'), - https: require.resolve('https-browserify'), - crypto: require.resolve('crypto-browserify'), - stream: require.resolve('readable-stream'), - }, - alias: { - // To avoid blotting up the `bn.js` library all over the packages - // use single library instance. - 'bn.js': path.resolve(__dirname, 'node_modules/bn.js'), - }, - }, - devtool: 'source-map', - plugins: [ - new CleanWebpackPlugin({ - verbose: true, - }), - new webpack.IgnorePlugin({ - checkResource(resource) { - // "@ethereumjs/common/genesisStates" consists ~800KB static files which are no more needed - return /(.*\/genesisStates\/.*\.json)/.test(resource); - }, - }), - new webpack.ProvidePlugin({ - Buffer: ['buffer', 'Buffer'], - }), - new webpack.ProvidePlugin({ - process: 'process/browser', - }), - ], -}; - -module.exports = () => { - return config; -};