From cd67597660a7a1b769d29c93ae46e7cb7287dca9 Mon Sep 17 00:00:00 2001 From: Kristofer Selbekk Date: Wed, 5 Oct 2016 13:12:42 +0200 Subject: [PATCH] Add root imports with tilde prefix This commit adds `babel-plugin-root-import` to the default .babelrc file to define `~` as the absolute path to the src/ folder. This gives us the possibility to turn code like this: ``` import SomeUtility from '../../utils/some-utility' ``` to this ``` import SomeUtility from '~/utils/some-utility'; ``` --- packages/babel-preset-react-app/index.js | 5 +++++ packages/babel-preset-react-app/package.json | 1 + 2 files changed, 6 insertions(+) diff --git a/packages/babel-preset-react-app/index.js b/packages/babel-preset-react-app/index.js index 34e9efabb72..0ec0fef3864 100644 --- a/packages/babel-preset-react-app/index.js +++ b/packages/babel-preset-react-app/index.js @@ -34,6 +34,11 @@ module.exports = { regenerator: true, // Resolve the Babel runtime relative to the config. moduleName: path.dirname(require.resolve('babel-runtime/package')) + }], + // resolve imports beginning with ~ as /src/{import} + [require.resolve('babel-root-import'), { + 'rootPathPrefix': '~', + 'rootPathSuffix': 'src' }] ] }; diff --git a/packages/babel-preset-react-app/package.json b/packages/babel-preset-react-app/package.json index f0ead1f3b50..2f47e24c828 100644 --- a/packages/babel-preset-react-app/package.json +++ b/packages/babel-preset-react-app/package.json @@ -20,6 +20,7 @@ "babel-plugin-transform-runtime": "6.15.0", "babel-preset-latest": "6.14.0", "babel-preset-react": "6.11.1", + "babel-root-import": "^4.1.3", "babel-runtime": "6.11.6" } }