Skip to content

Instantly share code, notes, and snippets.

@hrdtbs
Last active April 12, 2018 09:17
Show Gist options
  • Save hrdtbs/ae16a44d35c6128b38ccc2500a5ce34a to your computer and use it in GitHub Desktop.
Save hrdtbs/ae16a44d35c6128b38ccc2500a5ce34a to your computer and use it in GitHub Desktop.
Root import with Create-React-App

yarn add react-app-rewired babel-plugin-root-import --dev

"scripts": {
  "start": "react-app-rewired start",
  "build": "react-app-rewired build",
  "test": "react-app-rewired test --env=jsdom"
}
const { injectBabelPlugin } = require('react-app-rewired');
const rootImport = ['root-import', {
  rootPathPrefix: '~',
  rootPathSuffix: 'src',
}];
module.exports = function override(config, env) {
  config = injectBabelPlugin(rootImport, config);
  return config;
}

`~/components/Button'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment