mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
27 lines
965 B
JavaScript
27 lines
965 B
JavaScript
import { resolve } from 'path'
|
|
import glob from 'glob-promise'
|
|
import transpile from './transpile'
|
|
import bundle from './bundle'
|
|
|
|
export default async function build (dir) {
|
|
const dstDir = resolve(dir, '.next')
|
|
const templateDir = resolve(__dirname, '..', '..', 'lib', 'pages')
|
|
|
|
// create `.next/pages/_error.js`
|
|
// which may be overwriten by the user sciprt, `pages/_error.js`
|
|
const templatPaths = await glob('**/*.js', { cwd: templateDir })
|
|
await Promise.all(templatPaths.map(async (p) => {
|
|
await transpile(resolve(templateDir, p), resolve(dstDir, 'pages', p))
|
|
}))
|
|
|
|
const paths = await glob('**/*.js', { cwd: dir, ignore: 'node_modules/**' })
|
|
await Promise.all(paths.map(async (p) => {
|
|
await transpile(resolve(dir, p), resolve(dstDir, p))
|
|
}))
|
|
|
|
const pagePaths = await glob('pages/**/*.js', { cwd: dstDir })
|
|
await Promise.all(pagePaths.map(async (p) => {
|
|
await bundle(resolve(dstDir, p), resolve(dstDir, '_bundles', p))
|
|
}))
|
|
}
|