eslint-plugin-import: webpack doesn't resolve relative to `resolve.root`

webpack lets us define a value for resolve.root, and we can import modules relative to the root directly.

Eg:

File: webpack.config.js

resolve: {
  root: path.resolve('./jsx')
}

File: /jsx/components/Button.jsx

import React, { Component } from 'react'
export default class Button extends Component {
  render() {
    return <button {...this.props} />
  }
}

File: /jsx/Some/Deep/Nested/Dir/Component.jsx

import '../../../../components/Button'

can be written as

File: /jsx/Some/Deep/Nested/Dir/Component.jsx

import 'components/Button'

Since webpack config has defined a value for resolve.root, I can directly import from ‘components/Button’ rather than from ‘…/…/…/…/components/Button’. This syntax is super helpful when dealing with deep nested directory structures. It would be great if the webpack resolver package could support it.

Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 24 (8 by maintainers)

Commits related to this issue

Most upvoted comments

closing for now, if you can provide a failing test case we can reopen?