diff --git a/config/webpack.config.renderer.base.ts b/config/webpack.config.renderer.base.ts index da5a49f74..e4d931b3c 100644 --- a/config/webpack.config.renderer.base.ts +++ b/config/webpack.config.renderer.base.ts @@ -7,6 +7,8 @@ import { merge } from 'webpack-merge'; import baseConfig from './webpack.config.common'; import webpackPaths from './webpack.paths'; +import { EMOJI_CODE_POINTS } from '../src/renderer/utils/emojis'; + const configuration: webpack.Configuration = { devtool: 'inline-source-map', @@ -72,6 +74,12 @@ const configuration: webpack.Configuration = { 'svg', ), to: 'images/twemoji', + // Only copy the SVGs for the emojis we use + filter: (resourcePath) => { + return EMOJI_CODE_POINTS.some((svg) => + resourcePath.endsWith(`/${svg}.svg`), + ); + }, }, ], }), diff --git a/src/renderer/utils/__snapshots__/emojis.test.ts.snap b/src/renderer/utils/__snapshots__/emojis.test.ts.snap new file mode 100644 index 000000000..2e0c08668 --- /dev/null +++ b/src/renderer/utils/__snapshots__/emojis.test.ts.snap @@ -0,0 +1,26 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renderer/utils/emojis.ts emoji code points 1`] = ` +[ + "1f389", + "1f38a", + "1f973", + "1f44f", + "1f64c", + "1f60e", + "1f3d6-fe0f", + "1f680", + "2728", + "1f3c6", + "1f513", + "1f52d", + "1f6dc", + "1f62e-200d-1f4a8", + "1f914", + "1f972", + "1f633", + "1fae0", + "1f643", + "1f648", +] +`; diff --git a/src/renderer/utils/emojis.test.ts b/src/renderer/utils/emojis.test.ts new file mode 100644 index 000000000..62f5736a5 --- /dev/null +++ b/src/renderer/utils/emojis.test.ts @@ -0,0 +1,8 @@ +import { EMOJI_CODE_POINTS } from './emojis'; + +describe('renderer/utils/emojis.ts', () => { + it('emoji code points', () => { + expect(EMOJI_CODE_POINTS).toHaveLength(20); + expect(EMOJI_CODE_POINTS).toMatchSnapshot(); + }); +}); diff --git a/src/renderer/utils/emojis.ts b/src/renderer/utils/emojis.ts new file mode 100644 index 000000000..a733bf4a0 --- /dev/null +++ b/src/renderer/utils/emojis.ts @@ -0,0 +1,16 @@ +import twemoji from '@discordapp/twemoji'; +import { Constants } from './constants'; +import { Errors } from './errors'; + +const ALL_EMOJIS = [ + ...Constants.ALL_READ_EMOJIS, + ...Errors.BAD_CREDENTIALS.emojis, + ...Errors.MISSING_SCOPES.emojis, + ...Errors.NETWORK.emojis, + ...Errors.RATE_LIMITED.emojis, + ...Errors.UNKNOWN.emojis, +]; + +export const EMOJI_CODE_POINTS = ALL_EMOJIS.map((emoji) => + twemoji.convert.toCodePoint(emoji), +);