2017-06-08 17:41:22 +00:00
|
|
|
import { join } from 'path'
|
|
|
|
import { readdirSync, existsSync } from 'fs'
|
|
|
|
|
2017-12-05 23:46:06 +00:00
|
|
|
export const IS_BUNDLED_PAGE = /^bundles[/\\]pages.*\.(js|jsx)$/
|
|
|
|
export const MATCH_ROUTE_NAME = /^bundles[/\\]pages[/\\](.*)\.(js|jsx)$/
|
2017-06-08 17:41:22 +00:00
|
|
|
|
|
|
|
export function getAvailableChunks (dir, dist) {
|
|
|
|
const chunksDir = join(dir, dist, 'chunks')
|
|
|
|
if (!existsSync(chunksDir)) return {}
|
|
|
|
|
|
|
|
const chunksMap = {}
|
|
|
|
const chunkFiles = readdirSync(chunksDir)
|
|
|
|
|
|
|
|
chunkFiles.forEach(filename => {
|
|
|
|
if (/\.js$/.test(filename)) {
|
|
|
|
chunksMap[filename] = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return chunksMap
|
|
|
|
}
|