Webpack: move Twemoji icons back to CopyPlugin
This commit is contained in:
parent
139b47eb22
commit
5eab5ec0a5
6 changed files with 48 additions and 19 deletions
|
@ -1,6 +1,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import unicodeMapping from '../features/emoji/emoji_unicode_mapping_light';
|
import unicodeMapping from '../features/emoji/emoji_unicode_mapping_light';
|
||||||
|
import { joinPublicPath } from 'soapbox/utils/static';
|
||||||
|
|
||||||
export default class AutosuggestEmoji extends React.PureComponent {
|
export default class AutosuggestEmoji extends React.PureComponent {
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ export default class AutosuggestEmoji extends React.PureComponent {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
url = require(`twemoji/assets/svg/${mapping.filename}.svg`);
|
url = joinPublicPath(`packs/emoji/${mapping.filename}.svg`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -7,6 +7,7 @@ import classNames from 'classnames';
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
import { supportsPassiveEvents } from 'detect-passive-events';
|
import { supportsPassiveEvents } from 'detect-passive-events';
|
||||||
import { buildCustomEmojis } from '../../emoji/emoji';
|
import { buildCustomEmojis } from '../../emoji/emoji';
|
||||||
|
import { joinPublicPath } from 'soapbox/utils/static';
|
||||||
|
|
||||||
const messages = defineMessages({
|
const messages = defineMessages({
|
||||||
emoji: { id: 'emoji_button.label', defaultMessage: 'Insert emoji' },
|
emoji: { id: 'emoji_button.label', defaultMessage: 'Insert emoji' },
|
||||||
|
@ -357,7 +358,7 @@ class EmojiPickerDropdown extends React.PureComponent {
|
||||||
<img
|
<img
|
||||||
className={classNames('emojione', { 'pulse-loading': active && loading })}
|
className={classNames('emojione', { 'pulse-loading': active && loading })}
|
||||||
alt='😂'
|
alt='😂'
|
||||||
src={require('twemoji/assets/svg/1f602.svg')}
|
src={joinPublicPath('packs/emoji/1f602.svg')}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import unicodeMapping from './emoji_unicode_mapping_light';
|
import unicodeMapping from './emoji_unicode_mapping_light';
|
||||||
import Trie from 'substring-trie';
|
import Trie from 'substring-trie';
|
||||||
|
import { joinPublicPath } from 'soapbox/utils/static';
|
||||||
|
|
||||||
const trie = new Trie(Object.keys(unicodeMapping));
|
const trie = new Trie(Object.keys(unicodeMapping));
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ const emojify = (str, customEmojis = {}, autoplay = false) => {
|
||||||
} else { // matched to unicode emoji
|
} else { // matched to unicode emoji
|
||||||
const { filename, shortCode } = unicodeMapping[match];
|
const { filename, shortCode } = unicodeMapping[match];
|
||||||
const title = shortCode ? `:${shortCode}:` : '';
|
const title = shortCode ? `:${shortCode}:` : '';
|
||||||
const src = require(`twemoji/assets/svg/${filename}.svg`);
|
const src = joinPublicPath(`packs/emoji/${filename}.svg`);
|
||||||
replacement = `<img draggable="false" class="emojione" alt="${match}" title="${title}" src="${src}" />`;
|
replacement = `<img draggable="false" class="emojione" alt="${match}" title="${title}" src="${src}" />`;
|
||||||
rend = i + match.length;
|
rend = i + match.length;
|
||||||
// If the matched character was followed by VS15 (for selecting text presentation), skip it.
|
// If the matched character was followed by VS15 (for selecting text presentation), skip it.
|
||||||
|
|
11
app/soapbox/utils/static.js
Normal file
11
app/soapbox/utils/static.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
/**
|
||||||
|
* Static: functions related to static files.
|
||||||
|
* @module soapbox/utils/static
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { join } from 'path';
|
||||||
|
import { FE_SUBDIRECTORY } from 'soapbox/build_config';
|
||||||
|
|
||||||
|
export const joinPublicPath = (...paths) => {
|
||||||
|
return join(FE_SUBDIRECTORY, ...paths);
|
||||||
|
};
|
|
@ -1,11 +1,15 @@
|
||||||
// Note: You must restart bin/webpack-dev-server for changes to take effect
|
// Note: You must restart bin/webpack-dev-server for changes to take effect
|
||||||
console.log('Running in production mode'); // eslint-disable-line no-console
|
console.log('Running in production mode'); // eslint-disable-line no-console
|
||||||
|
|
||||||
|
const { join } = require('path');
|
||||||
const { merge } = require('webpack-merge');
|
const { merge } = require('webpack-merge');
|
||||||
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
||||||
const OfflinePlugin = require('@lcdp/offline-plugin');
|
const OfflinePlugin = require('@lcdp/offline-plugin');
|
||||||
const sharedConfig = require('./shared');
|
const sharedConfig = require('./shared');
|
||||||
|
|
||||||
|
const { FE_SUBDIRECTORY } = require(join(__dirname, '..', 'app', 'soapbox', 'build_config'));
|
||||||
|
const joinPublicPath = (...paths) => join(FE_SUBDIRECTORY, ...paths);
|
||||||
|
|
||||||
module.exports = merge(sharedConfig, {
|
module.exports = merge(sharedConfig, {
|
||||||
mode: 'production',
|
mode: 'production',
|
||||||
devtool: 'source-map',
|
devtool: 'source-map',
|
||||||
|
@ -26,28 +30,32 @@ module.exports = merge(sharedConfig, {
|
||||||
caches: {
|
caches: {
|
||||||
main: [':rest:'],
|
main: [':rest:'],
|
||||||
additional: [
|
additional: [
|
||||||
'packs/emoji/1f602-*.svg', // used for emoji picker dropdown
|
':externals:',
|
||||||
'packs/images/32-*.png', // used in emoji-mart
|
'packs/images/32-*.png', // used in emoji-mart
|
||||||
|
|
||||||
// Default emoji reacts
|
|
||||||
'packs/emoji/1f44d-*.svg', // Thumbs up
|
|
||||||
'packs/emoji/2764-*.svg', // Heart
|
|
||||||
'packs/emoji/1f606-*.svg', // Laughing
|
|
||||||
'packs/emoji/1f62e-*.svg', // Surprised
|
|
||||||
'packs/emoji/1f622-*.svg', // Crying
|
|
||||||
'packs/emoji/1f629-*.svg', // Weary
|
|
||||||
'packs/emoji/1f621-*.svg', // Angry (Spinster)
|
|
||||||
],
|
],
|
||||||
optional: [
|
optional: [
|
||||||
'**/locale_*.js', // don't fetch every locale; the user only needs one
|
'**/locale_*.js', // don't fetch every locale; the user only needs one
|
||||||
'**/*_polyfills-*.js', // the user may not need polyfills
|
'**/*_polyfills-*.js', // the user may not need polyfills
|
||||||
'**/*.chunk.js', // only cache chunks when needed
|
'**/*.chunk.js', // only cache chunks when needed
|
||||||
|
'**/*.chunk.css',
|
||||||
'**/*.woff2', // the user may have system-fonts enabled
|
'**/*.woff2', // the user may have system-fonts enabled
|
||||||
// images can be cached on-demand
|
// images can be cached on-demand
|
||||||
'**/*.png',
|
'**/*.png',
|
||||||
'**/*.svg',
|
'**/*.svg',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
externals: [
|
||||||
|
joinPublicPath('packs/emoji/1f602.svg'), // used for emoji picker dropdown
|
||||||
|
|
||||||
|
// Default emoji reacts
|
||||||
|
joinPublicPath('packs/emoji/1f44d.svg'), // Thumbs up
|
||||||
|
joinPublicPath('packs/emoji/2764.svg'), // Heart
|
||||||
|
joinPublicPath('packs/emoji/1f606.svg'), // Laughing
|
||||||
|
joinPublicPath('packs/emoji/1f62e.svg'), // Surprised
|
||||||
|
joinPublicPath('packs/emoji/1f622.svg'), // Crying
|
||||||
|
joinPublicPath('packs/emoji/1f629.svg'), // Weary
|
||||||
|
joinPublicPath('packs/emoji/1f621.svg'), // Angry (Spinster)
|
||||||
|
],
|
||||||
excludes: [
|
excludes: [
|
||||||
'**/*.gz',
|
'**/*.gz',
|
||||||
'**/*.map',
|
'**/*.map',
|
||||||
|
@ -69,12 +77,16 @@ module.exports = merge(sharedConfig, {
|
||||||
// https://github.com/bromite/bromite/issues/1294
|
// https://github.com/bromite/bromite/issues/1294
|
||||||
'index.html',
|
'index.html',
|
||||||
'404.html',
|
'404.html',
|
||||||
|
'assets-manifest.json',
|
||||||
|
// It would be nice to serve these, but they bloat up sw.js
|
||||||
|
'packs/images/crypto/**/*',
|
||||||
|
'packs/emoji/**/*',
|
||||||
],
|
],
|
||||||
// ServiceWorker: {
|
ServiceWorker: {
|
||||||
// entry: join(__dirname, '../app/soapbox/service_worker/entry.js'),
|
// entry: join(__dirname, '../app/soapbox/service_worker/entry.js'),
|
||||||
// cacheName: 'soapbox',
|
// cacheName: 'soapbox',
|
||||||
// minify: true,
|
minify: true,
|
||||||
// },
|
},
|
||||||
safeToUseOptionalCaches: true,
|
safeToUseOptionalCaches: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
|
|
@ -88,6 +88,9 @@ module.exports = {
|
||||||
new HtmlWebpackHarddiskPlugin(),
|
new HtmlWebpackHarddiskPlugin(),
|
||||||
new CopyPlugin({
|
new CopyPlugin({
|
||||||
patterns: [{
|
patterns: [{
|
||||||
|
from: join(__dirname, '../node_modules/twemoji/assets/svg'),
|
||||||
|
to: join(output.path, 'packs/emoji'),
|
||||||
|
}, {
|
||||||
from: join(__dirname, '../app/instance'),
|
from: join(__dirname, '../app/instance'),
|
||||||
to: join(output.path, 'instance'),
|
to: join(output.path, 'instance'),
|
||||||
}],
|
}],
|
||||||
|
|
Loading…
Reference in a new issue