Skip to content

Commit 59d1986

Browse files
committed
chore: split build files into smaller chunks
1 parent f8e66d0 commit 59d1986

File tree

8 files changed

+83
-17
lines changed

8 files changed

+83
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const { merge } = require('webpack-merge');
22

3-
const createDevConfig = require('./webpack.common.dev');
4-
const appConfig = require('./webpack.common.app');
3+
const commonDevConfig = require('./webpack.common.dev');
4+
const commonAppConfig = require('./webpack.common.app');
55
require('dotenv-defaults').config({
66
path: './.env',
77
encoding: 'utf8',
88
defaults: process.env.BUILD_DEV_PREVIEW === 'true' ? './.env.developerpreview' : './.env.defaults'
99
});
1010

11-
module.exports = (env) => merge(createDevConfig({ devServerPort: 3001 })(env), appConfig());
11+
module.exports = (env) => merge(commonDevConfig({ devServerPort: 3001 })(env), commonAppConfig());
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { merge } = require('webpack-merge');
22

3-
const prodConfig = require('./webpack.common.prod');
4-
const appConfig = require('./webpack.common.app');
3+
const commonProdConfig = require('./webpack.common.prod');
4+
const commonAppConfig = require('./webpack.common.app');
55

66
const hasSentryReleaseConfig =
77
!!process.env.SENTRY_AUTH_TOKEN && !!process.env.SENTRY_ORG && !!process.env.SENTRY_PROJECT;
@@ -12,4 +12,4 @@ require('dotenv-defaults').config({
1212
defaults: process.env.BUILD_DEV_PREVIEW === 'true' ? './.env.developerpreview' : './.env.defaults'
1313
});
1414

15-
module.exports = () => merge(prodConfig(), appConfig(hasSentryReleaseConfig));
15+
module.exports = () => merge(commonProdConfig(), commonAppConfig(hasSentryReleaseConfig));

apps/browser-extension-wallet/webpack.common.js

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module.exports = () => {
2626
output: {
2727
path: path.join(__dirname, 'dist/js'),
2828
filename: '[name].js',
29+
chunkFilename: '[name].[contenthash].chunk.js',
2930
// the following setting is required for SRI to work:
3031
crossOriginLoading: 'anonymous'
3132
},

apps/browser-extension-wallet/webpack.common.prod.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require('dotenv-defaults').config({
1111

1212
module.exports = () => ({
1313
mode: 'production',
14-
devtool: 'source-map',
14+
devtool: false,
1515
plugins: [
1616
new Dotenv({
1717
path: '.env',
@@ -75,6 +75,19 @@ module.exports = () => ({
7575
}
7676
}
7777
})
78-
]
78+
],
79+
splitChunks: {
80+
chunks: 'all',
81+
maxSize: 3000000, // 3MB
82+
cacheGroups: {
83+
vendor: {
84+
test: /[\\/]node_modules[\\/]/,
85+
name: 'vendor',
86+
chunks: 'all',
87+
priority: 1,
88+
reuseExistingChunk: true
89+
}
90+
}
91+
}
7992
}
8093
});
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const { merge } = require('webpack-merge');
22

3-
const createDevConfig = require('./webpack.common.dev');
4-
const swConfig = require('./webpack.common.sw');
3+
const commonDevConfig = require('./webpack.common.dev');
4+
const commonSwConfig = require('./webpack.common.sw');
55
require('dotenv-defaults').config({
66
path: './.env',
77
encoding: 'utf8',
88
defaults: process.env.BUILD_DEV_PREVIEW === 'true' ? './.env.developerpreview' : './.env.defaults'
99
});
1010

11-
module.exports = (env) => merge(createDevConfig({ devServerPort: 3000 })(env), swConfig());
11+
module.exports = (env) => merge(commonDevConfig({ devServerPort: 3000 })(env), commonSwConfig());

apps/browser-extension-wallet/webpack.sw.prod.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { merge } = require('webpack-merge');
22

3-
const prodConfig = require('./webpack.common.prod');
4-
const swConfig = require('./webpack.common.sw');
3+
const commonProdConfig = require('./webpack.common.prod');
4+
const commonSwConfig = require('./webpack.common.sw');
55
require('dotenv-defaults').config({
66
path: './.env',
77
encoding: 'utf8',
@@ -10,8 +10,8 @@ require('dotenv-defaults').config({
1010

1111
module.exports = () =>
1212
merge(
13-
prodConfig(),
14-
swConfig(),
13+
commonProdConfig(),
14+
commonSwConfig(),
1515
// Needed for the service worker to work with a production build
1616
// TODO: after removing imports from dist/cjs, service worker no longer loads when built in production mode.
1717
// It is likely that some optimization is triggering it, such as tree shaking.

packages/nami/src/ui/app/components/transaction.tsx

+19-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ import {
2828
FaUsers,
2929
FaRegFileCode,
3030
} from 'react-icons/fa';
31-
import { GiAnvilImpact } from 'react-icons/gi';
31+
3232
import { IoRemoveCircleSharp } from 'react-icons/io5';
33+
import { GenIcon } from 'react-icons/lib';
3334
import {
3435
TiArrowForward,
3536
TiArrowBack,
@@ -53,6 +54,23 @@ import { contextLogger } from '@cardano-sdk/util';
5354

5455
TimeAgo.addDefaultLocale(en);
5556

57+
// extracted from `react-icons/gi` as react-icons does not support tree-shaking
58+
// and the whole library is imported and exceeds Mozilla's 4MB file limit
59+
const GiAnvilImpact = () =>
60+
GenIcon({
61+
tag: 'svg',
62+
attr: { viewBox: '0 0 512 512' },
63+
child: [
64+
{
65+
tag: 'path',
66+
attr: {
67+
d: 'M413.375 69.906L336.937 191.47l-8.25-32.69-30.218 88.97 62.655-29.375.22 29.438 127.03-50.938-70.813-1.97 47.782-68.686-73.47 39.25 21.5-95.564zM210.22 102.094l-32 14.406 16.874 55.656-177.813 80.03 12.564 27.876L207.656 200l30.406 49.47 49.313-22.19-21.344-70.343-55.81-54.843zM197.593 266.78v20.345h-88.906c15.994 38.807 51.225 65.43 88.906 74.28v32.97h58.562c-12.118 30.528-33.505 55.684-58.47 77.594H172.22v18.686H456.56V471.97h-27.406c-28.734-21.895-50.055-47.018-61.625-77.595h63.658v-29.188c19.748-6.995 39.5-19.51 59.25-36.687-19.812-17.523-39.23-27.25-59.25-31.938v-29.78H197.594z',
68+
},
69+
child: [],
70+
},
71+
],
72+
})({});
73+
5674
const txTypeColor = {
5775
self: 'gray.500',
5876
internalIn: 'teal.500',

packages/nami/src/ui/app/pages/wallet.tsx

+35-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ import {
6363
BsClockHistory,
6464
} from 'react-icons/bs';
6565
import { FaGamepad, FaRegFileCode } from 'react-icons/fa';
66-
import { GiTwoCoins, GiUsbKey } from 'react-icons/gi';
66+
import { GenIcon } from 'react-icons/lib';
6767
import { useHistory } from 'react-router-dom';
6868

6969
import { getNextAccountIndex } from '../../../adapters/account';
@@ -120,6 +120,40 @@ export type Props = Pick<
120120
environmentName: OutsideHandlesContextValue['environmentName'];
121121
};
122122

123+
// extracted from `react-icons/gi` as react-icons does not support tree-shaking
124+
// and the whole library is imported and exceeds Mozilla's 4MB file limit
125+
const GiUsbKey = () =>
126+
GenIcon({
127+
tag: 'svg',
128+
attr: { viewBox: '0 0 512 512' },
129+
child: [
130+
{
131+
tag: 'path',
132+
attr: {
133+
d: 'M394.8 30.88l-65 65.03 86.3 86.29 65.1-65-86.4-86.32zm-6.3 36.04l17 17-12.8 12.72-17-17 12.8-12.72zm-82.8 30.4l-11.3 11.28 109 108.9 11.3-11.2-109-108.98zM263.3 103L23.4 342.9v60.5l85.2 85.2h60.5l240-239.9L263.3 103zm164.9 3.6l16.9 17-12.8 12.6-16.9-17 12.8-12.6z',
134+
},
135+
child: [],
136+
},
137+
],
138+
})({});
139+
140+
// extracted from `react-icons/gi` as react-icons does not support tree-shaking
141+
// and the whole library is imported and exceeds Mozilla's 4MB file limit
142+
const GiTwoCoins = () =>
143+
GenIcon({
144+
tag: 'svg',
145+
attr: { viewBox: '0 0 512 512' },
146+
child: [
147+
{
148+
tag: 'path',
149+
attr: {
150+
d: 'M264.4 95.01c-35.6-.06-80.2 11.19-124.2 34.09C96.27 152 61.45 182 41.01 211.3c-20.45 29.2-25.98 56.4-15.92 75.8 10.07 19.3 35.53 30.4 71.22 30.4 35.69.1 80.29-11.2 124.19-34 44-22.9 78.8-53 99.2-82.2 20.5-29.2 25.9-56.4 15.9-75.8-10.1-19.3-35.5-30.49-71.2-30.49zm91.9 70.29c-3.5 15.3-11.1 31-21.8 46.3-22.6 32.3-59.5 63.8-105.7 87.8-46.2 24.1-93.1 36.2-132.5 36.2-18.6 0-35.84-2.8-50.37-8.7l10.59 20.4c10.08 19.4 35.47 30.5 71.18 30.5 35.7 0 80.3-11.2 124.2-34.1 44-22.8 78.8-52.9 99.2-82.2 20.4-29.2 26-56.4 15.9-75.7zm28.8 16.8c11.2 26.7 2.2 59.2-19.2 89.7-18.9 27.1-47.8 53.4-83.6 75.4 11.1 1.2 22.7 1.8 34.5 1.8 49.5 0 94.3-10.6 125.9-27.1 31.7-16.5 49.1-38.1 49.1-59.9 0-21.8-17.4-43.4-49.1-59.9-16.1-8.4-35.7-15.3-57.6-20zm106.7 124.8c-10.2 11.9-24.2 22.4-40.7 31-35 18.2-82.2 29.1-134.3 29.1-21.2 0-41.6-1.8-60.7-5.2-23.2 11.7-46.5 20.4-68.9 26.1 1.2.7 2.4 1.3 3.7 2 31.6 16.5 76.4 27.1 125.9 27.1s94.3-10.6 125.9-27.1c31.7-16.5 49.1-38.1 49.1-59.9z',
151+
},
152+
child: [],
153+
},
154+
],
155+
})({});
156+
123157
const Wallet = ({
124158
activeAddress,
125159
currency,

0 commit comments

Comments
 (0)