1 | const fs = require('fs-extra')
|
2 | const getChunkmapPath = require('./get-chunkmap-path')
|
3 | const getDistPath = require('./get-dist-path')
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | const getChunkmap = (localeId, getFullResult = false) => {
|
13 | if (localeId === true) return getChunkmap(getFullResult || undefined, true)
|
14 |
|
15 | if (typeof localeId === 'undefined') {
|
16 | try {
|
17 | localeId = require('../i18n').localeId
|
18 | } catch (e) { }
|
19 | }
|
20 |
|
21 | const i18nType = JSON.parse(process.env.KOOT_I18N)
|
22 | ? JSON.parse(process.env.KOOT_I18N_TYPE)
|
23 | : undefined
|
24 | const isI18nDefault = (i18nType === 'default')
|
25 |
|
26 | let chunkmap
|
27 | if (typeof global.chunkmap === 'object') chunkmap = global.chunkmap
|
28 | try {
|
29 | chunkmap = JSON.parse(process.env.WEBPACK_CHUNKMAP)
|
30 | } catch (e) {
|
31 | chunkmap = false
|
32 | }
|
33 |
|
34 | if (typeof chunkmap !== 'object' && typeof getDistPath() === 'string') {
|
35 | chunkmap = fs.readJsonSync(getChunkmapPath())
|
36 | if (process.env.WEBPACK_BUILD_STAGE === 'server')
|
37 | global.chunkmap = chunkmap
|
38 | }
|
39 |
|
40 | if (typeof chunkmap === 'object') {
|
41 |
|
42 | if (getFullResult) return chunkmap || {}
|
43 | if (isI18nDefault) chunkmap = chunkmap[`.${localeId}`] || {}
|
44 | }
|
45 |
|
46 | return chunkmap || {}
|
47 | }
|
48 |
|
49 | module.exports = getChunkmap
|