{"id":19212,"library":"babel-plugin-transform-react-router-optimize","title":"babel-plugin-transform-react-router-optimize","description":"A Babel plugin that automatically rewrites ES2015 imports from 'react-router' (v2/v3) to direct file imports under '/lib', enabling bundle size optimization by cherry-picking only the used components. Stable at v1.0.2, released September 2017. Requires react-router >=2.0.0. Designed for Babel 6, not compatible with Babel 5. Key differentiator: eliminates manual import rewriting for React Router bundle optimization.","status":"maintenance","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/nerdlabs/babel-plugin-transform-react-router-optimize","tags":["javascript","babel-plugin","react-router","optimization","minify","react","reactjs"],"install":[{"cmd":"npm install babel-plugin-transform-react-router-optimize","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-transform-react-router-optimize","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-transform-react-router-optimize","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency, plugin transforms imports from react-router","package":"react-router","optional":false}],"imports":[{"note":"Default export is the Babel plugin function. CommonJS require works too, but default import is typical for Babel plugins.","wrong":"const plugin = require('babel-plugin-transform-react-router-optimize');","symbol":"Plugin (default)","correct":"import plugin from 'babel-plugin-transform-react-router-optimize';"},{"note":"In .babelrc, use the plugin name string. No need to import.","wrong":"","symbol":"Plugin in .babelrc (String)","correct":"{\n  \"plugins\": [\"transform-react-router-optimize\"]\n}"},{"note":"For programmatic use, pass plugin name as string in plugins array.","wrong":"","symbol":"Plugin usage via Node API","correct":"const babel = require('babel-core');\nbabel.transform(code, { plugins: ['transform-react-router-optimize'] });"}],"quickstart":{"code":"// .babelrc example\n{\n  \"plugins\": [\"transform-react-router-optimize\"]\n}\n\n// Input: \nimport { Route, IndexRoute } from 'react-router';\n\n// Output (transformed by plugin):\nimport Route from 'react-router/lib/Route';\nimport IndexRoute from 'react-router/lib/IndexRoute';","lang":"javascript","description":"Shows .babelrc config and transformation from top-level import to per-file imports for smaller bundles."},"warnings":[{"fix":"Upgrade to Babel 6 or use a different plugin for Babel 7 (e.g., transform-imports).","message":"This plugin is for Babel 6 only. It will not work with Babel 5 or Babel 7+.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use ES2016 import syntax for react-router imports.","message":"Only supports ES2015 import statements. Requires and other module systems are not transformed.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure you import from 'react-router' top-level, not subpaths.","message":"Plugin only transforms imports from 'react-router'. Imports from subpaths like 'react-router/lib' are left unchanged.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For react-router v4+, use tree-shaking with webpack or babel-plugin-transform-imports.","message":"React Router v4+ does not support direct file imports under /lib. This plugin is only useful for react-router v2/v3.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Add \"presets\": [\"es2015\"] to .babelrc or install babel-preset-es2015.","cause":"Babel 6 requires explicit presets; missing es2015 preset for transpilation.","error":"Error: Couldn't find preset \"es2015\" relative to directory ..."},{"fix":"Use react-router v2 or v3, or switch to a different optimization approach.","cause":"Plugin tries to resolve to a specific file, but that file doesn't exist (e.g., in react-router v4).","error":"Module not found: Error: Can't resolve 'react-router/lib/Route'"},{"fix":"Ensure your build pipeline uses Babel with appropriate presets (es2015 or env).","cause":"Babel is not configured to transpile ES6 modules; the plugin runs before transpilation.","error":"SyntaxError: ... unexpected token import"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}