frontity
Version:
Frontity cli and entry point to other packages
43 lines (42 loc) • 1.51 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = __importDefault(require("chalk"));
const utils_1 = require("../utils");
/**
* Build the project for production.
*
* This function is executed by the CLI when running the `npx frontity build`
* command.
*
* @param options - Object of type {@link BuildOptions}.
*/
const buildCommand = async ({ development = false, target = "both", publicPath = "/static/", analyze = false, }) => {
// Try getting the `build` function from `@frontity/core`.
let build;
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
build = require("@frontity/core").build;
}
catch (error) {
const message = `Make sure that you are running ${chalk_1.default.green("frontity")} inside a Frontity project.\n` +
`If so try installing ${chalk_1.default.green("@frontity/core")} again with ${chalk_1.default.green("npm i @frontity/core")}.\n`;
utils_1.errorLogger(error, message);
}
// Generate options for the core's `build` function.
const options = {
mode: development ? "development" : "production",
target,
publicPath,
analyze,
};
try {
await build(options);
}
catch (error) {
utils_1.errorLogger(error);
}
};
exports.default = buildCommand;