{"version":3,"sources":["../../src/build/get-babel-loader-config.ts"],"sourcesContent":["import type { EnvironmentConfig } from 'babel-plugin-react-compiler'\nimport path from 'path'\nimport type { JSONValue, ReactCompilerOptions } from '../server/config-shared'\nimport type { NextBabelLoaderOptions } from './babel/loader/types'\n\nfunction getReactCompiler() {\n try {\n return require.resolve('babel-plugin-react-compiler')\n } catch {\n throw new Error(\n 'Failed to load the `babel-plugin-react-compiler`. It is required to use the React Compiler. Please install it.'\n )\n }\n}\n\nconst getReactCompilerPlugins = (\n maybeOptions: boolean | ReactCompilerOptions | undefined,\n isServer: boolean,\n isDev: boolean\n): undefined | JSONValue[] => {\n if (!maybeOptions || isServer) {\n return undefined\n }\n\n const environment: Pick = {\n enableNameAnonymousFunctions: isDev,\n }\n const options: ReactCompilerOptions =\n typeof maybeOptions === 'boolean' ? {} : maybeOptions\n const compilerOptions: JSONValue = {\n ...options,\n environment,\n }\n return [[getReactCompiler(), compilerOptions]]\n}\n\nconst getBabelLoader = (\n useSWCLoader: boolean | undefined,\n babelConfigFile: string | undefined,\n isServer: boolean,\n distDir: string,\n pagesDir: string | undefined,\n cwd: string,\n srcDir: string,\n dev: boolean,\n isClient: boolean,\n reactCompilerOptions: boolean | ReactCompilerOptions | undefined,\n reactCompilerExclude: ((excludePath: string) => boolean) | undefined\n) => {\n if (!useSWCLoader) {\n // Make sure these options are kept in sync with\n // `packages/next/src/build/get-babel-loader-config.ts`\n const options: NextBabelLoaderOptions = {\n transformMode: 'default',\n configFile: babelConfigFile,\n isServer,\n distDir,\n pagesDir,\n cwd,\n srcDir: path.dirname(srcDir),\n development: dev,\n hasReactRefresh: dev && isClient,\n hasJsxRuntime: true,\n reactCompilerPlugins: getReactCompilerPlugins(\n reactCompilerOptions,\n isServer,\n dev\n ),\n reactCompilerExclude,\n }\n return {\n loader: require.resolve('./babel/loader/index'),\n options,\n }\n }\n\n return undefined\n}\n\n/**\n * Get a separate babel loader for the react compiler, only used if Babel is not\n * configured through e.g. .babelrc. If user have babel config, this should be configured in the babel loader itself.\n * Note from react compiler:\n * > For best results, compiler must run as the first plugin in your Babel pipeline so it receives input as close to the original source as possible.\n */\nconst getReactCompilerLoader = (\n reactCompilerOptions: boolean | ReactCompilerOptions | undefined,\n cwd: string,\n isServer: boolean,\n reactCompilerExclude: ((excludePath: string) => boolean) | undefined,\n isDev: boolean\n) => {\n const reactCompilerPlugins = getReactCompilerPlugins(\n reactCompilerOptions,\n isServer,\n isDev\n )\n if (!reactCompilerPlugins) {\n return undefined\n }\n\n const babelLoaderOptions: NextBabelLoaderOptions = {\n transformMode: 'standalone',\n cwd,\n reactCompilerPlugins,\n isServer,\n }\n if (reactCompilerExclude) {\n babelLoaderOptions.reactCompilerExclude = reactCompilerExclude\n }\n\n return {\n loader: require.resolve('./babel/loader/index'),\n options: babelLoaderOptions,\n }\n}\n\nexport { getBabelLoader, getReactCompilerLoader }\n"],"names":["getBabelLoader","getReactCompilerLoader","getReactCompiler","require","resolve","Error","getReactCompilerPlugins","maybeOptions","isServer","isDev","undefined","environment","enableNameAnonymousFunctions","options","compilerOptions","useSWCLoader","babelConfigFile","distDir","pagesDir","cwd","srcDir","dev","isClient","reactCompilerOptions","reactCompilerExclude","transformMode","configFile","path","dirname","development","hasReactRefresh","hasJsxRuntime","reactCompilerPlugins","loader","babelLoaderOptions"],"mappings":";;;;;;;;;;;;;;;IAqHSA,cAAc;eAAdA;;IAAgBC,sBAAsB;eAAtBA;;;6DApHR;;;;;;AAIjB,SAASC;IACP,IAAI;QACF,OAAOC,QAAQC,OAAO,CAAC;IACzB,EAAE,OAAM;QACN,MAAM,qBAEL,CAFK,IAAIC,MACR,mHADI,qBAAA;mBAAA;wBAAA;0BAAA;QAEN;IACF;AACF;AAEA,MAAMC,0BAA0B,CAC9BC,cACAC,UACAC;IAEA,IAAI,CAACF,gBAAgBC,UAAU;QAC7B,OAAOE;IACT;IAEA,MAAMC,cAAuE;QAC3EC,8BAA8BH;IAChC;IACA,MAAMI,UACJ,OAAON,iBA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