mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
0c4362e440
* Always check with the fs when gettings chunks. * Add a new set of test cases for dynamic imports in dev. * Add dynamic import test cases for production. * Add availableChunks support for static exports.
22 lines
540 B
JavaScript
22 lines
540 B
JavaScript
import { join } from 'path'
|
|
import { readdirSync, existsSync } from 'fs'
|
|
|
|
export const IS_BUNDLED_PAGE = /^bundles[/\\]pages.*\.js$/
|
|
export const MATCH_ROUTE_NAME = /^bundles[/\\]pages[/\\](.*)\.js$/
|
|
|
|
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
|
|
}
|