Files
stacks.js/configs/webpack.config.js
janniks 5445b73e05 feat!: switch from buffer to uint8array (#1343)
BREAKING CHANGE:
Removes compatibility with `bip32` package from @stacks/wallet-sdk. Now all derivation methods only rely on HDKey from @scure/bip32.

BREAKING CHANGE:
To reduce the bundle sizes of applications using Stacks.js we are moving away from Buffer (a polyfill to match Node.js APIs) to Uint8Arrays (which Buffers use in the background anyway). To make the switch easier we have introduced a variety of methods for converting between strings and Uint8Arrays: `hexToBytes`, `bytesToHex`, `utf8ToBytes`, `bytesToUtf8`, `asciiToBytes`, `bytesToAscii`, and `concatBytes`.

Co-authored-by: janniks <janniks@users.noreply.github.com>
2022-09-30 11:35:58 +02:00

73 lines
2.2 KiB
JavaScript

const webpack = require('webpack');
const path = require('path');
// Run with ANALYZE ENV to show bundle size (only works with cjs)
// e.g.: ANALYZE=true lerna run --scope @stacks/wallet-sdk build
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const { DuplicatesPlugin } = require('inspectpack/plugin');
const NODE_ENV_PRODUCTION = 'production';
const NODE_ENV_DEVELOPMENT = 'development';
const isAnalyze = !!process.env.ANALYZE;
const isProduction = process.env.NODE_ENV === NODE_ENV_PRODUCTION;
module.exports = {
mode: isProduction ? NODE_ENV_PRODUCTION : NODE_ENV_DEVELOPMENT,
entry: ['./src/index.ts'],
output: {
library: {
// name: is set in package config
type: isAnalyze ? 'commonjs' : 'umd',
},
filename: 'index.js',
path: path.resolve(process.cwd(), 'dist/umd'),
globalObject: 'this', // recommended for umd bundles in webpack
},
plugins: [
new webpack.ProvidePlugin({
process: require.resolve('process/browser'),
}),
isAnalyze && new DuplicatesPlugin(),
isAnalyze && new BundleAnalyzerPlugin({ analyzerMode: 'static' }),
].filter(Boolean),
optimization: {
minimize: isProduction,
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{
loader: 'esbuild-loader',
options: {
loader: 'tsx',
target: 'es2017',
tsconfigRaw: require(path.resolve(process.cwd(), 'tsconfig.build.json')),
},
},
],
},
],
},
resolve: {
extensions: ['.ts', '.js'],
alias: {
'@stacks/auth': '@stacks/auth/dist/esm',
'@stacks/bns': '@stacks/bns/dist/esm',
'@stacks/common': '@stacks/common/dist/esm',
'@stacks/encryption': '@stacks/encryption/dist/esm',
'@stacks/keychain': '@stacks/keychain/dist/esm',
'@stacks/network': '@stacks/network/dist/esm',
'@stacks/profile': '@stacks/profile/dist/esm',
'@stacks/stacking': '@stacks/stacking/dist/esm',
'@stacks/storage': '@stacks/storage/dist/esm',
'@stacks/transactions': '@stacks/transactions/dist/esm',
'@stacks/wallet-sdk': '@stacks/wallet-sdk/dist/esm',
},
// fallback: is set in package config
},
};