mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-05 05:15:48 +00:00
Switch to using fetch for browser and `node-fetch` for node for the faucet calls. This reduces the webpack bundle by 3.2% or 16.5kb gzipped. The fundWallet code has been refactored to be much more straight forward due to not having to do such low level operations. This improves the frontend setup process by no longer requiring several polyfills such as `url`, `stream-http`, and `https-browserify`.
92 lines
2.6 KiB
JavaScript
92 lines
2.6 KiB
JavaScript
'use strict'
|
|
const path = require('path')
|
|
const webpack = require('webpack')
|
|
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
|
|
|
|
const bnJsReplaces = [
|
|
'tiny-secp256k1',
|
|
'asn1.js',
|
|
'create-ecdh',
|
|
'miller-rabin',
|
|
'public-encrypt',
|
|
'elliptic',
|
|
]
|
|
|
|
function getDefaultConfiguration() {
|
|
return {
|
|
cache: true,
|
|
performance: { hints: false },
|
|
stats: 'errors-only',
|
|
entry: './dist/npm/index.js',
|
|
output: {
|
|
library: 'xrpl',
|
|
path: path.join(__dirname, 'build/'),
|
|
filename: `xrpl.default.js`,
|
|
},
|
|
devtool: 'source-map',
|
|
plugins: [
|
|
new webpack.NormalModuleReplacementPlugin(/^ws$/, './WSWrapper'),
|
|
new webpack.ProvidePlugin({ process: 'process/browser' }),
|
|
new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'] }),
|
|
new webpack.IgnorePlugin({
|
|
resourceRegExp: /^\.\/wordlists\/(?!english)/,
|
|
contextRegExp: /bip39\/src$/,
|
|
}),
|
|
// this is a bit of a hack to prevent 'bn.js' from being installed 6 times
|
|
// TODO: any package that is updated to use bn.js 5.x needs to be removed from `bnJsReplaces` above
|
|
// https://github.com/webpack/webpack/issues/5593#issuecomment-390356276
|
|
new webpack.NormalModuleReplacementPlugin(/^bn.js$/, (resource) => {
|
|
if (
|
|
bnJsReplaces.some((pkg) =>
|
|
resource.context.includes(`node_modules/${pkg}`),
|
|
)
|
|
) {
|
|
resource.request = 'diffie-hellman/node_modules/bn.js'
|
|
}
|
|
}),
|
|
],
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.js$/,
|
|
use: ['source-map-loader'],
|
|
},
|
|
],
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
ws: './dist/npm/client/WSWrapper.js',
|
|
},
|
|
extensions: ['.js', '.json'],
|
|
// We don't want to webpack any of the local dependencies:
|
|
// ripple-address-codec, ripple-binary-codec, ripple-keypairs, which are
|
|
// symlinked together via lerna
|
|
symlinks: false,
|
|
fallback: {
|
|
buffer: require.resolve('buffer/'),
|
|
assert: require.resolve('assert/'),
|
|
stream: require.resolve('stream-browserify'),
|
|
crypto: require.resolve('crypto-browserify'),
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
module.exports = [
|
|
(env, argv) => {
|
|
const config = getDefaultConfiguration()
|
|
config.mode = 'development'
|
|
config.output.filename = `xrpl-latest.js`
|
|
return config
|
|
},
|
|
(env, argv) => {
|
|
const config = getDefaultConfiguration()
|
|
config.mode = 'production'
|
|
config.output.filename = `xrpl-latest-min.js`
|
|
if (process.argv.includes('--analyze')) {
|
|
config.plugins.push(new BundleAnalyzerPlugin())
|
|
}
|
|
return config
|
|
},
|
|
]
|