react-universally icon indicating copy to clipboard operation
react-universally copied to clipboard

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

Open datoml opened this issue 9 years ago • 7 comments

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'

datoml avatar Jan 11 '17 13:01 datoml

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

frankleng avatar Jan 11 '17 16:01 frankleng

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

codepunkt avatar Jan 11 '17 19:01 codepunkt

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
        }, {})
      }))

bradennapier avatar Jan 11 '17 21:01 bradennapier

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.

frankleng avatar Jan 11 '17 23:01 frankleng

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 :).

datoml avatar Jan 12 '17 07:01 datoml

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

ctrlplusb avatar Jan 12 '17 08:01 ctrlplusb

@ctrlplusb Thats a good idea :).

datoml avatar Jan 12 '17 09:01 datoml