UNPKG

@berun/runner-static

Version:

Cross build engine preset for building static applications

75 lines (63 loc) 1.98 kB
import * as path from 'path' import * as fs from 'fs-extra' function getRunner(berun) { if ('webpack' in berun) { return require('@berun/runner-webpack').default } throw new Error( 'Static preset only supports webpack currently; cannot find either of these in berun use chain' ) } /* * Sparky Task to run first of two-pass web-pack build * to create static react website */ export const taskStaticPass1 = async (berun) => { const { taskBuildPreFlightClean, taskBuildCopyPublicAssets, taskBuildCompile } = getRunner(berun) await taskStaticPreFlightArgs(berun) await taskBuildPreFlightClean(berun) await taskBuildCopyPublicAssets(berun) berun.sparkyContext.buildMessage = 'Creating first pass of production static build...' await taskBuildCompile(berun) } /* * Sparky Task to run second of two-pass web-pack build * to create static react website */ export const taskStaticPass2 = async (berun) => { const { taskBuildCopyPublicAssets, taskBuildCompile, taskBuildPostFlightInstructions } = getRunner(berun) await taskBuildCopyPublicAssets(berun) berun.sparkyContext.buildMessage = 'Creating second pass of production static build...' await taskBuildCompile(berun) if (berun.sparkyContext.noJS) { await taskStaticRemoveJS(berun) } await taskBuildPostFlightInstructions(berun) } async function taskStaticPreFlightArgs(berun) { const argv = process.argv.slice(2) berun.sparkyContext.noJS = argv.indexOf('--js') === -1 berun.sparkyContext.shouldCompareFileSizes = false berun.sparkyContext.writeStatsJson = false berun.sparkyContext.isSPA = false } const taskStaticRemoveJS = async (berun) => { const bundle = path.join(berun.options.paths.appBuild, './main.js') await fs.remove(bundle) } const taskDev = (berun) => { const runner = getRunner(berun) return runner.taskDev(berun) } export { taskStaticPreFlightArgs, taskStaticRemoveJS } export const taskStaticDev = taskDev