/
githubmirror
/
styled-components
Обзор
Документация
Войти
/
githubmirror
/
styled-components
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
babel-preset.cjs
38 строк
1 KB
Evan Jacobs
chore: tooling refresh + drop stylis + Expo SDK 56 lockfile bump
19 май 2026, 06:53
19 май 2026, 06:53
e6a5919
Код
Авторство
О чём код?
const { BABEL_ENV, NODE_ENV } = process.env; const modules = BABEL_ENV === 'cjs' || NODE_ENV === 'test' ? 'commonjs' : false; const isReactNativeFile = filepath => /[\\/]node_modules[\\/](?:react-native|@react-native(?:-community)?)[\\/]/.test(filepath); module.exports = () => ({ presets: [ [ '@babel/preset-env', { targets: NODE_ENV === 'test' ? { node: 'current' } : undefined, loose: true, modules, }, ], '@babel/preset-react', '@babel/preset-typescript', ], plugins: ['@babel/plugin-transform-flow-strip-types'], overrides: [ // Our own build uses `add-module-exports` so CJS consumers get the default // export at `require(...)` directly. RN's source assumes native ESM->CJS // semantics (`.default` access) - applying `add-module-exports` there // collapses `module.exports = exports.default` and breaks `require('.../PixelRatio').default`. // Gate it to SC's own sources only. modules === 'commonjs' && { test: filepath => !isReactNativeFile(filepath), plugins: ['add-module-exports'], }, // RN source ships as a mix of Flow, TypeScript, and JSX. Route its // files to @react-native/babel-preset - the canonical parser for RN source. { test: filepath => isReactNativeFile(filepath), presets: [['@react-native/babel-preset', { disableImportExportTransform: false }]], }, ].filter(Boolean), });