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 | const isI18nEnabled = JSON.parse(process.env.KOOT_I18N) === false ? false : true
|
16 |
|
17 | if (isI18nEnabled && typeof localeId === 'undefined') {
|
18 | try {
|
19 | localeId = require('../index').localeId
|
20 | } catch (e) { }
|
21 | }
|
22 |
|
23 | const i18nType = isI18nEnabled && JSON.parse(process.env.KOOT_I18N)
|
24 | ? JSON.parse(process.env.KOOT_I18N_TYPE)
|
25 | : undefined
|
26 | const isI18nDefault = (isI18nEnabled && i18nType === 'default')
|
27 |
|
28 | let chunkmap
|
29 | if (typeof global.chunkmap === 'object') chunkmap = global.chunkmap
|
30 | try {
|
31 | chunkmap = JSON.parse(process.env.WEBPACK_CHUNKMAP)
|
32 | } catch (e) {
|
33 | chunkmap = false
|
34 | }
|
35 |
|
36 | if (typeof chunkmap !== 'object' && typeof getDistPath() === 'string') {
|
37 | chunkmap = fs.readJsonSync(getChunkmapPath())
|
38 | if (process.env.WEBPACK_BUILD_STAGE === 'server')
|
39 | global.chunkmap = chunkmap
|
40 | }
|
41 |
|
42 | if (typeof chunkmap === 'object') {
|
43 |
|
44 | if (getFullResult) return chunkmap || {}
|
45 | if (isI18nEnabled && isI18nDefault) chunkmap = chunkmap[`.${localeId}`] || {}
|
46 | }
|
47 |
|
48 | return chunkmap || {}
|
49 | }
|
50 |
|
51 | module.exports = getChunkmap
|