Remove emoji annotations code for unused languages from final build
This commit is contained in:
parent
1bdf67c08d
commit
7661bb69ff
4 changed files with 71 additions and 5 deletions
64
build/emojis_plugin.js
Normal file
64
build/emojis_plugin.js
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
import { resolve } from 'node:path'
|
||||||
|
import { access } from 'node:fs/promises'
|
||||||
|
import { languages, langCodeToCldrName } from '../src/i18n/languages.js'
|
||||||
|
|
||||||
|
const annotationsImportPrefix = '@kazvmoe-infra/unicode-emoji-json/annotations/'
|
||||||
|
const specialAnnotationsLocale = {
|
||||||
|
ja_easy: 'ja'
|
||||||
|
}
|
||||||
|
|
||||||
|
const internalToAnnotationsLocale = (internal) => specialAnnotationsLocale[internal] || internal
|
||||||
|
|
||||||
|
// This gets all the annotations that are accessible (whose language
|
||||||
|
// can be chosen in the settings). Data for other languages are
|
||||||
|
// discarded because there is no way for it to be fetched.
|
||||||
|
const getAllAccessibleAnnotations = async (projectRoot) => {
|
||||||
|
const imports = (await Promise.all(
|
||||||
|
languages
|
||||||
|
.map(async lang => {
|
||||||
|
const destLang = internalToAnnotationsLocale(lang)
|
||||||
|
const importModule = `${annotationsImportPrefix}${destLang}.json`
|
||||||
|
const importFile = resolve(projectRoot, 'node_modules', importModule)
|
||||||
|
try {
|
||||||
|
await access(importFile)
|
||||||
|
return `'${lang}': () => import('${importModule}')`
|
||||||
|
} catch (e) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})))
|
||||||
|
.filter(k => k)
|
||||||
|
.join(',\n')
|
||||||
|
|
||||||
|
return `
|
||||||
|
export const annotationsLoader = {
|
||||||
|
${imports}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
}
|
||||||
|
|
||||||
|
const emojiAnnotationsId = 'virtual:pleroma-fe/emoji-annotations'
|
||||||
|
const emojiAnnotationsIdResolved = '\0' + emojiAnnotationsId
|
||||||
|
|
||||||
|
const emojisPlugin = () => {
|
||||||
|
let projectRoot
|
||||||
|
return {
|
||||||
|
name: 'emojis-plugin',
|
||||||
|
configResolved (conf) {
|
||||||
|
projectRoot = conf.root
|
||||||
|
},
|
||||||
|
resolveId (id) {
|
||||||
|
if (id === emojiAnnotationsId) {
|
||||||
|
return emojiAnnotationsIdResolved
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
},
|
||||||
|
async load (id) {
|
||||||
|
if (id === emojiAnnotationsIdResolved) {
|
||||||
|
return await getAllAccessibleAnnotations(projectRoot)
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default emojisPlugin
|
||||||
1
changelog.d/emoji-handling.remove
Normal file
1
changelog.d/emoji-handling.remove
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Remove emoji annotations code for unused languages from final build
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
import apiService from '../services/api/api.service.js'
|
import apiService from '../services/api/api.service.js'
|
||||||
import { instanceDefaultProperties } from './config.js'
|
import { instanceDefaultProperties } from './config.js'
|
||||||
import { langCodeToCldrName, ensureFinalFallback } from '../i18n/languages.js'
|
import { ensureFinalFallback } from '../i18n/languages.js'
|
||||||
import { useInterfaceStore } from 'src/stores/interface.js'
|
import { useInterfaceStore } from 'src/stores/interface.js'
|
||||||
|
// See build/emojis_plugin for more details
|
||||||
|
import { annotationsLoader } from 'virtual:pleroma-fe/emoji-annotations'
|
||||||
|
|
||||||
const SORTED_EMOJI_GROUP_IDS = [
|
const SORTED_EMOJI_GROUP_IDS = [
|
||||||
'smileys-and-emotion',
|
'smileys-and-emotion',
|
||||||
|
|
@ -179,10 +181,7 @@ const defaultState = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadAnnotations = (lang) => {
|
const loadAnnotations = (lang) => {
|
||||||
const code = langCodeToCldrName(lang)
|
return annotationsLoader[lang]()
|
||||||
return import(
|
|
||||||
`../../node_modules/@kazvmoe-infra/unicode-emoji-json/annotations/${code}.json`
|
|
||||||
)
|
|
||||||
.then(k => k.default)
|
.then(k => k.default)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import vue from '@vitejs/plugin-vue'
|
||||||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||||
import stylelint from 'vite-plugin-stylelint'
|
import stylelint from 'vite-plugin-stylelint'
|
||||||
import eslint from 'vite-plugin-eslint2'
|
import eslint from 'vite-plugin-eslint2'
|
||||||
|
import emojisPlugin from './build/emojis_plugin.js'
|
||||||
import { devSwPlugin, buildSwPlugin, swMessagesPlugin } from './build/sw_plugin.js'
|
import { devSwPlugin, buildSwPlugin, swMessagesPlugin } from './build/sw_plugin.js'
|
||||||
import copyPlugin from './build/copy_plugin.js'
|
import copyPlugin from './build/copy_plugin.js'
|
||||||
import { getCommitHash } from './build/commit_hash.js'
|
import { getCommitHash } from './build/commit_hash.js'
|
||||||
|
|
@ -104,6 +105,7 @@ export default defineConfig(async ({ mode, command }) => {
|
||||||
devSwPlugin({ swSrc, swDest, transformSW, alias }),
|
devSwPlugin({ swSrc, swDest, transformSW, alias }),
|
||||||
buildSwPlugin({ swSrc, swDest }),
|
buildSwPlugin({ swSrc, swDest }),
|
||||||
swMessagesPlugin(),
|
swMessagesPlugin(),
|
||||||
|
emojisPlugin(),
|
||||||
copyPlugin({
|
copyPlugin({
|
||||||
inUrl: '/static/ruffle',
|
inUrl: '/static/ruffle',
|
||||||
inFs: resolve(projectRoot, 'node_modules/@ruffle-rs/ruffle')
|
inFs: resolve(projectRoot, 'node_modules/@ruffle-rs/ruffle')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue