Add option to minify generated code in backend package

Signed-off-by: Jonathan Roebuck <jroebuck@spotify.com>
This commit is contained in:
Jonathan Roebuck
2024-03-13 15:43:32 +00:00
parent 5c3e1865a8
commit fe1a55efe4
6 changed files with 19 additions and 6 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---
Extend option to minify generated code to the `backend` package.
+1 -1
View File
@@ -128,7 +128,7 @@ Build a package for production deployment or publishing
Options:
--role <name> Run the command with an explicit package role
--minify Minify the generated code. Does not apply to app or backend packages.
--minify Minify the generated code. Does not apply to app package (app is minified by default).
--skip-build-dependencies Skip the automatic building of local dependencies. Applies to backend packages only.
--stats If bundle stats are available, write them to the output directory. Applies to app packages only.
--config <path> Config files to load instead of app-config.yaml. Applies to app packages only. (default: [])
@@ -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',
@@ -102,6 +102,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') {
@@ -204,8 +209,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,
});
}
}