1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/server/utils.js
Arunoda Susiripala 337fb6a9aa Remove buildId from dynamic import URLs (#3498)
* Use without .js for the filename.

* Modify the chunk filename to add .js via webpack

* Add import chunk's hash to the filename via webpack.

* Remove buildId from dynamic import urls.

* Make sure next-export work with dynamic imports
2017-12-27 19:59:17 +01:00

23 lines
609 B
JavaScript

import { join } from 'path'
import { readdirSync, existsSync } from 'fs'
export const IS_BUNDLED_PAGE = /^bundles[/\\]pages.*\.(js|jsx)$/
export const MATCH_ROUTE_NAME = /^bundles[/\\]pages[/\\](.*)\.(js|jsx)$/
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)) {
const chunkName = filename.replace(/-.*/, '')
chunksMap[chunkName] = filename
}
})
return chunksMap
}