Skip to content

Commit

Permalink
feat(react): allow setting react preset to production when using cust…
Browse files Browse the repository at this point in the history
…om BABEL_ENV (#19148)
  • Loading branch information
AgentEnder authored Sep 13, 2023
1 parent 7975950 commit dc8b408
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions packages/react/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

interface NxReactBabelOptions {
development?: boolean;
runtime?: string;
importSource?: string;
useBuiltIns?: boolean | string;
Expand Down Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/executors/file-server/file-server.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down

0 comments on commit dc8b408

Please sign in to comment.