UNPKG

@roots/bud

Version:

Configurable, extensible build tools for modern single and multi-page web applications

163 lines (160 loc) 5.67 kB
import BudCommand from '@roots/bud/cli/commands'; import browserslistUpdate from '@roots/bud/cli/flags/browserslist-update'; import ci from '@roots/bud/cli/flags/ci'; import dashboard from '@roots/bud/cli/flags/dashboard'; import dashboardAssets from '@roots/bud/cli/flags/dashboard.assets'; import dashboardCompact from '@roots/bud/cli/flags/dashboard.compact'; import dashboardEntrypoints from '@roots/bud/cli/flags/dashboard.entrypoints'; import dashboardServer from '@roots/bud/cli/flags/dashboard.server'; import devtool from '@roots/bud/cli/flags/devtool'; import discover from '@roots/bud/cli/flags/discover'; import dry from '@roots/bud/cli/flags/dry'; import editor from '@roots/bud/cli/flags/editor'; import entrypointsHtml from '@roots/bud/cli/flags/entrypoints.html'; import esm from '@roots/bud/cli/flags/esm'; import hash from '@roots/bud/cli/flags/hash'; import html from '@roots/bud/cli/flags/html'; import immutable from '@roots/bud/cli/flags/immutable'; import lazy from '@roots/bud/cli/flags/lazy'; import minimize from '@roots/bud/cli/flags/minimize'; import runtime from '@roots/bud/cli/flags/runtime'; import silent from '@roots/bud/cli/flags/silent'; import splitChunks from '@roots/bud/cli/flags/splitChunks'; import browserslistUpdateCheck from '@roots/bud/cli/helpers/browserslistUpdate'; import budUpdateCheck from '@roots/bud/cli/helpers/budUpdate'; import isBoolean from '@roots/bud-support/isBoolean'; import isString from '@roots/bud-support/isString'; import noop from '@roots/bud-support/noop'; /** * `bud build` command */ export default class BudBuildCommand extends BudCommand { /** * {@link BudCommand.paths} */ static paths = [[`build`]]; /** * {@link BudCommand.usage} */ static usage = BudCommand.Usage({ category: `build`, description: `Compile source assets`, details: `\ \`bud build production\` compiles source assets in \`production\` mode. Run \`bud build production --help\` for usage. \`bud build development\` compiles source assets in \`development\` mode and serves updated modules. Run \`bud build development --help\` for usage. If you run this command without a configuration file \`bud\` will look for an entrypoint at \`@src/index.js\`. `, }); browserslistUpdate = browserslistUpdate; [`dashboard.assets`] = dashboardAssets; [`dashboard.compact`] = dashboardCompact; [`dashboard.entrypoints`] = dashboardEntrypoints; [`dashboard.server`] = dashboardServer; [`dashboard`] = dashboard; [`entrypoints.html`] = entrypointsHtml; ci = ci; devtool = devtool; discover = discover; dry = dry(false); editor = editor; esm = esm; hash = hash; hot; html = html; immutable = immutable; lazy = lazy; minimize = minimize; proxy; runtime = runtime; silent = silent(false); splitChunks = splitChunks; /** * {@link BudCommand.execute} */ async execute() { await this.makeBud(); if (isBoolean(this[`entrypoints.html`]) && `entrypoints` in this.bud) { this.bud.entrypoints.set(`emitHtml`, this[`entrypoints.html`]); } await Promise.all([ [ this.browserslistUpdate, `BUD_BROWSERSLIST_UPDATE`, `browserslistUpdate`, b => async (v) => (b.root.context.browserslistUpdate = v), false, ], [ this.devtool, `BUD_DEVTOOL`, `devtool`, b => async (v) => b.devtool(v), ], [ this.esm, `BUD_ESM`, `esm`, b => async (v) => b.esm.enable(v), ], [ this.hash, `BUD_HASH`, `hash`, b => async (value) => b.hash(value), ], [ this.hot, `BUD_HOT`, `hot`, b => async (v) => b.root.hooks.on(`dev.middleware.enabled`, ware => ware?.filter(key => (v === false ? key !== `hot` : v)) ?? []), ], [ this.html, `BUD_HTML`, `html`, b => async (v) => isString(v) ? b.html({ template: v }) : b.html(v), ], [ this.immutable, `BUD_IMMUTABLE`, `immutable`, b => async (v) => b.cdn.freeze(v), ], [ this.lazy, `BUD_LAZY`, `lazy`, b => async (v) => b.lazy(v), ], [ this.minimize, `BUD_MINIMIZE`, `minimize`, b => async (v) => b.minimize(v), ], [ this.proxy, `BUD_PROXY_URL`, `proxy.url`, b => async (v) => b.root.hooks.on(`dev.middleware.proxy.options.target`, new URL(v)), false, ], [ this.runtime, `BUD_RUNTIME`, `runtime`, b => async (v) => b.runtime(v), ], [ this.splitChunks, `BUD_SPLIT_CHUNKS`, `splitChunks`, b => async (v) => b.splitChunks(v), ], ].map(this.override)).catch(noop); await browserslistUpdateCheck(this.bud); await budUpdateCheck(this.bud); await this.bud.run(); } }