Tree shaking Support Guide
- Use the
production
mode configuration option to enable various optimizations including minification and tree shaking. Set your webpack.config:
"mode":"production"
- Add a
sideEffects
property to your project'spackage.json
file:
"sideEffects": false
note
For further information about sideEffects
see webpack docs
::: 3. Set your tsconfig module to ES2015
or higher to support imports
, because tree shaking does not work with require
:
"module": "ES2015"
-
Use the specific packages which you need,
For example, if you need
web.eth
:
- JavaScript
- TypeScript
const Web3Eth = require('web3-eth');
// ...
import Web3Eth from 'web3-eth';
// ...
If you only need a few functions from web3-utils
:
- JavaScript
- TypeScript
const { numberToHex, hexToNumber } = require('web3-utils');
// ...
import { numberToHex, hexToNumber } from 'web3-utils';
// ...
You can find an example app with tree shaking here.