Bundle service worker conditionally
This commit is contained in:
parent
cca5e31f56
commit
eb6d9cdd4b
4 changed files with 108 additions and 44 deletions
|
|
@ -3,14 +3,20 @@ import { readFile } from 'node:fs/promises'
|
|||
import { dirname, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const i18nDir = resolve(
|
||||
dirname(dirname(fileURLToPath(import.meta.url))),
|
||||
'src/i18n'
|
||||
)
|
||||
|
||||
export const i18nFiles = languages.reduce((acc, lang) => {
|
||||
const name = langCodeToJsonName(lang)
|
||||
const file = resolve(i18nDir, name + '.json')
|
||||
acc[lang] = file
|
||||
return acc
|
||||
}, {})
|
||||
|
||||
export const generateServiceWorkerMessages = async () => {
|
||||
const i18nDir = resolve(
|
||||
dirname(dirname(fileURLToPath(import.meta.url))),
|
||||
'src/i18n'
|
||||
)
|
||||
const msgArray = await Promise.all(languages.map(async lang => {
|
||||
const name = langCodeToJsonName(lang)
|
||||
const file = resolve(i18nDir, name + '.json')
|
||||
const msgArray = await Promise.all(Object.entries(i18nFiles).map(async ([lang, file]) => {
|
||||
const fileContent = await readFile(file, 'utf-8')
|
||||
const msg = {
|
||||
notifications: JSON.parse(fileContent).notifications || {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue