# gatsby-plugin-resolve-src

> Gatsby plugin to allow resolving imports from the src subdirectory

Latest version **2.1.0** (published 2020-04-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install gatsby-plugin-resolve-src
pnpm add gatsby-plugin-resolve-src
yarn add gatsby-plugin-resolve-src
bun add gatsby-plugin-resolve-src
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2020-04-25 |
| First published | 2017-07-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 37 |
| Author | Aaron Lampros |
| Maintainers | alampros |
| Keywords | gatsby, gatsby-plugin |

## Links

- npm: https://www.npmjs.com/package/gatsby-plugin-resolve-src
- Repository: https://github.com/alampros/gatsby-plugin-resolve-src
- Homepage: https://github.com/alampros/gatsby-plugin-resolve-src#readme
- Issues: https://github.com/alampros/gatsby-plugin-resolve-src/issues
- npm.io page: https://npm.io/package/gatsby-plugin-resolve-src

## Recent versions

- 2.1.0 (latest) — 2020-04-25
- 2.0.0 — 2019-02-04
- 2.0.0-beta.1 — 2018-07-10
- 1.1.4 — 2018-07-10
- 1.1.3 — 2018-04-10
- 1.1.2 — 2018-04-10
- 1.1.0 — 2018-04-03
- 1.0.0 — 2017-07-26

## README

# gatsby-plugin-resolve-src
Gatsby plugin to resolve imports from your project's `/src` directory

This plugin modifies your webpack config to allow imports from your `/src` directory, such as:

```js
import MyComponent from 'components/MyComponent'
```

...instead of

```js
import MyComponent from '../../components/MyComponent'
```

# Usage

Add it to your project

```sh
yarn add gatsby-plugin-resolve-src
```

Then add it to your `gatsby-config.js`:

```js
{
  plugins: [
    'gatsby-plugin-resolve-src',
  ]
}
```

## VSCode Configuration

You have to tell VS Code how to find your modules by creating a `tsconfig.json` (or `jsconfig.json`) file in your project root. For example:

```json
{
  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "*": [
        "types/*",
        "*"
      ]
    }
  },
}
```

See [#9](https://github.com/alampros/gatsby-plugin-resolve-src/issues/9) for more info.

## ESLint Configuration

If using `eslint-plugin-import`, you have to tell ESLint how to find your modules by configuring the default `node` resolver in your eslint config. For example:

```json
{
  "settings": {
    "import/resolver": {
      "node": {
        "moduleDirectory": ["node_modules", "src"]
      }
    }
  }
}
```

If your project is linting filetypes besides `.js`, you will have to add them explicitly. See the node resolver [documentation](https://www.npmjs.com/package/eslint-import-resolver-node) for more details.

## Options

### `srcPath` (file path)

Default: `path.resolve(__dirname, '../../src')`

The full path to your `/src` directory.

#### Yarn Workspaces

To resolve your `src` directory when using yarn workspaces, use the srcPath option:

```
{
  resolve: 'gatsby-plugin-resolve-src',
  options: {
    srcPath: path.resolve(__dirname, 'src'),
  },
},
```

---
_Source: https://npm.io/package/gatsby-plugin-resolve-src · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
