UNPKG

745 BJavaScriptView Raw
1// import { localeId } from '../i18n'
2
3/**
4 * 获取 service-worker 文件名
5 * @param {String} [localeId] 如果提供,则会返回 [NAME].[localeId].js
6 * @returns {String}
7 */
8module.exports = (localeId) => {
9
10 if (typeof process.env.KOOT_PWA_PATHNAME !== 'string')
11 return ''
12
13 const i18nType = JSON.parse(process.env.KOOT_I18N)
14 ? JSON.parse(process.env.KOOT_I18N_TYPE)
15 : undefined
16
17 const pwaPathname = JSON.parse(process.env.KOOT_PWA_PATHNAME)
18
19 if (i18nType !== 'default')
20 return pwaPathname
21
22 if (!localeId)
23 return pwaPathname
24
25 const chunks = pwaPathname.split('.')
26 chunks.splice(chunks.length - 1, 0, localeId)
27 return chunks.join('.')
28
29}