feat(react): allow setting react preset to production when using custom BABEL_ENV (#19148)

This commit is contained in:
Craigory Coppola 2023-09-13 17:14:52 -04:00 committed by GitHub
parent 7975950a8c
commit dc8b408b1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -3,6 +3,7 @@
*/
interface NxReactBabelOptions {
development?: boolean;
runtime?: string;
importSource?: string;
useBuiltIns?: boolean | string;
@ -51,10 +52,16 @@ module.exports = function (api: any, options: NxReactBabelOptions) {
};
};
function getReactPresetOptions({ presetOptions, env }) {
function getReactPresetOptions({
presetOptions,
env,
}: {
env: string;
presetOptions: NxReactBabelOptions;
}) {
const reactPresetOptions: Record<string, string | boolean> = {
runtime: presetOptions.runtime ?? 'automatic',
development: env !== 'production',
development: presetOptions.development ?? env !== 'production',
};
// JSX spread is transformed into object spread in `@babel/plugin-transform-react-jsx`

View File

@ -70,7 +70,7 @@ function getBuildTargetOutputPath(options: Schema, context: ExecutorContext) {
let buildOptions;
try {
const target = parseTargetString(options.buildTarget, context.projectGraph);
const target = parseTargetString(options.buildTarget, context);
buildOptions = readTargetOptions(target, context);
} catch (e) {
throw new Error(`Invalid buildTarget: ${options.buildTarget}`);