Merge pull request #23493 from backstage/backend-package-minify-option

Add minify option to buildBackend and command
This commit is contained in:
Patrik Oldsberg
2024-03-19 14:53:55 +01:00
committed by GitHub
7 changed files with 20 additions and 6 deletions
@@ -29,17 +29,19 @@ interface BuildBackendOptions {
targetDir: string;
skipBuildDependencies: boolean;
configPaths?: string[];
minify?: boolean;
}
export async function buildBackend(options: BuildBackendOptions) {
const { targetDir, skipBuildDependencies, configPaths } = options;
const { targetDir, skipBuildDependencies, configPaths, minify } = options;
const pkg = await fs.readJson(resolvePath(targetDir, 'package.json'));
// We build the target package without generating type declarations.
await buildPackage({
targetDir: options.targetDir,
targetDir,
packageJson: pkg,
outputs: new Set([Output.cjs]),
minify,
});
const tmpDir = await fs.mkdtemp(resolvePath(os.tmpdir(), 'backstage-bundle'));
@@ -51,6 +53,7 @@ export async function buildBackend(options: BuildBackendOptions) {
buildExcludes: [pkg.name],
parallelism: getEnvironmentParallelism(),
skeleton: SKELETON_FILE,
minify,
});
// We built the target backend package using the regular build process, but the result of
@@ -45,6 +45,7 @@ export async function command(opts: OptionValues): Promise<void> {
targetDir: paths.targetDir,
configPaths,
skipBuildDependencies: Boolean(opts.skipBuildDependencies),
minify: Boolean(opts.minify),
});
}
+1 -1
View File
@@ -128,7 +128,7 @@ export function registerScriptCommand(program: Command) {
.option('--role <name>', 'Run the command with an explicit package role')
.option(
'--minify',
'Minify the generated code. Does not apply to app or backend packages.',
'Minify the generated code. Does not apply to app package (app is minified by default).',
)
.option(
'--skip-build-dependencies',
+1
View File
@@ -179,6 +179,7 @@ export async function command(opts: OptionValues, cmd: Command): Promise<void> {
await buildBackend({
targetDir: pkg.dir,
skipBuildDependencies: true,
minify: buildOptions.minify,
});
},
});
@@ -103,6 +103,11 @@ type Options = {
* command performance.
*/
alwaysYarnPack?: boolean;
/**
* If set to true, the generated code will be minified.
*/
minify?: boolean;
};
function prefixLogFunc(prefix: string, out: 'stdout' | 'stderr') {
@@ -205,8 +210,7 @@ export async function createDistWorkspace(
packageJson: pkg.packageJson,
outputs: outputs,
logPrefix: `${chalk.cyan(relativePath(paths.targetRoot, pkg.dir))}: `,
// No need to detect these for the backend builds, we assume no minification or types
minify: false,
minify: options.minify,
});
}
}