Skip to content

Commit

Permalink
feat(react): improve babel preset options (#10940)
Browse files Browse the repository at this point in the history
Improved the '@nrwl/react/babel' preset to allow for customisation of all options provided by
the
'@nrwl/web/babel' preset.

ISSUES CLOSED: #10939

Co-authored-by: Jason Gerbes <jason.gerbes@vista.co>
  • Loading branch information
jasongerbes and jasongerbes-vista committed Sep 22, 2022
1 parent 0baae01 commit 4dc331c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
11 changes: 5 additions & 6 deletions packages/react/babel.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import type { NxWebBabelPresetOptions } from '@nrwl/web';

/*
* Babel preset to provide React support for Nx.
*/

interface ReactBabelOptions {
interface NxReactBabelOptions extends NxWebBabelPresetOptions {
runtime?: string;
importSource?: string;
useBuiltIns?: boolean | string;
}

module.exports = function (api: any, options: ReactBabelOptions) {
module.exports = function (api: any, options: NxReactBabelOptions) {
api.assertVersion(7);
const env = api.env();
/**
* pagesDir is set when being transpiled by Next.js
*/
const isNextJs = api.caller((caller) => caller?.pagesDir);

const presets: any[] = [
['@nrwl/web/babel', { useBuiltIns: options.useBuiltIns }],
];
const presets: any[] = [['@nrwl/web/babel', options]];

/**
* Next.js already includes the preset-react, and including it
Expand Down
4 changes: 2 additions & 2 deletions packages/web/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { dirname } from 'path';
* Babel preset to provide TypeScript support and module/nomodule for Nx.
*/

interface NxReactBabelPresetOptions {
export interface NxWebBabelPresetOptions {
useBuiltIns?: boolean | string;
decorators?: {
decoratorsBeforeExport?: boolean;
Expand All @@ -15,7 +15,7 @@ interface NxReactBabelPresetOptions {
};
}

module.exports = function (api: any, options: NxReactBabelPresetOptions = {}) {
module.exports = function (api: any, options: NxWebBabelPresetOptions = {}) {
api.assertVersion(7);

const isModern = api.caller((caller) => caller?.isModern);
Expand Down
1 change: 1 addition & 0 deletions packages/web/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { webInitGenerator } from './src/generators/init/init';
export { applicationGenerator } from './src/generators/application/application';
export type { NxWebBabelPresetOptions } from './babel';

0 comments on commit 4dc331c

Please sign in to comment.