[FAQ] Specifying an import root to avoid relative import paths
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'
+1 already doing this in my setup. Will file a PR later today.
As a reference, see the discussion in #203 - which doesn't mean this can't be done :)
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
}, {})
}))
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.
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 :).
It's a common enough request that perhaps we should put something like @bradennapier's suggestion into the FAQ section?
@ctrlplusb Thats a good idea :).