Skip to content
This repository has been archived by the owner on Jun 3, 2019. It is now read-only.

[FAQ] Specifying an import root to avoid relative import paths #318

Open
datoml opened this issue Jan 11, 2017 · 7 comments
Open

[FAQ] Specifying an import root to avoid relative import paths #318

datoml opened this issue Jan 11, 2017 · 7 comments

Comments

@datoml
Copy link
Contributor

datoml commented Jan 11, 2017

Hello,

Maybe its a good idea to add this line to the webpack resolve module:
modules: ['src/shared','node_modules'],

So you are able to import your components like this:

import Navbar from 'components/Navbar'

@frankleng
Copy link

+1 already doing this in my setup.
Will file a PR later today.

@codepunkt
Copy link
Collaborator

As a reference, see the discussion in #203 - which doesn't mean this can't be done :)

@bradennapier
Copy link

bradennapier commented Jan 11, 2017

Perhaps a simple configuration variable so that it can be done outside of modifying the factory for devs? Not too hard for most of us to add it but for new devs it would likely be appealing and those that don't want it can simply turn it off.

I did that with aliases so I could just define a webpack_aliases: {} in the config using

ifElse(config.webpack_aliases)(() => ({
        alias: Object.keys(config.webpack_aliases).reduce((p, c) => {
          const a = config.webpack_aliases[c]
          if ( a.startsWith('~') && ! a.startsWith('~/') ) {
            p[c] = path.resolve(appRootDir.get(), a.replace('~', ''))
          } else { p[c] = a }
          return p
        }, {})
      }))

@frankleng
Copy link

as per #203 concern with IDE is fairly trivial. at least in WebStorm you can simply mark shared as a resource root. and clickthrough works brilliantly.

@datoml
Copy link
Contributor Author

datoml commented Jan 12, 2017

Like @codepunkt said in #203:
I would leave this up to the developer. You can't (and shouldn't) tackle every problem.

Wasn't aware of this discussion.
We can close this one I guess :).

@ctrlplusb
Copy link
Owner

It's a common enough request that perhaps we should put something like @bradennapier's suggestion into the FAQ section?

@datoml
Copy link
Contributor Author

datoml commented Jan 12, 2017

@ctrlplusb Thats a good idea :).

@ctrlplusb ctrlplusb changed the title Improve dev experience with webpack's resolve [FAQ] Specifying an import root to avoid relative import paths Feb 12, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants