An extend scope plugin for craco / react-scripts / create-react-app
npm install @dvhb/craco-extend-scopeBy default create-react-app don't allow you to import modules outside of
/src dir, it throws error like this:Relative imports outside of src/ are not supported. This plugin extends CRA config to add custom paths to
ModuleScopePlugin.
craco-extend-scope is tested with:
- react-scripts: ^2.1.5
- @craco/craco: ^3.5.0
First, follow the craco Installation Instructions
to install the craco package, create a craco.config.js file, and modify the scripts in your package.json.
Then install craco-extend-scope:
``bash
$ npm i @dvhb/craco-extend-scope
$ yarn add @dvhb/craco-extend-scope
`
Here is a complete craco.config.js configuration file that extends scope of create-react-app:
`js
const cracoExtendScope = require('./craco-extend-scope');
module.exports = {
plugins: [{ plugin: cracoExtendScope, options: { path: 'static' } }]
};
`
Now you can use absolute import in you code like this:
`js``
import 'static/styles.css';