UNPKG

@roots/bud-api

Version:

bud.js core module

37 lines (36 loc) 1.41 kB
import { isAbsolute } from 'node:path'; import isBoolean from '@roots/bud-support/isBoolean'; import isFunction from '@roots/bud-support/isFunction'; import isObject from '@roots/bud-support/isObject'; import isString from '@roots/bud-support/isString'; import isUndefined from '@roots/bud-support/isUndefined'; import omit from '@roots/bud-support/omit'; /** * Set HTML template */ export const html = async function (options = true) { const isEnabled = options !== false; const html = this.extensions.get(`@roots/bud-extensions/html-webpack-plugin`); const interpolate = this.extensions.get(`@roots/bud-extensions/interpolate-html-webpack-plugin`); html.enable(isEnabled); interpolate.enable(isEnabled); if (isBoolean(options)) return this; if (isFunction(options)) { html.setOptions(options(html.options ?? {})); return this; } if (isString(options)) { html.set(`template`, this.path(options)); return this; } if (isObject(options)) { if (!isUndefined(options.template) && !isAbsolute(options.template)) options.template = this.path(options.template); Object.entries(omit(options, `replace`)).forEach(([k, v]) => html.set(k, v)); if (isObject(options.replace)) { Object.entries(options.replace).forEach(v => interpolate.set(...v)); } } return this; };