webpack-dynamic-resolver v1.0.5
Webpack Dynamic Resolver
Motivation
I could not be as flexible as I'd like to be with webpack aliases, and I started to be tired of relative paths (../../
and so on...), so I decided to create this package.
Description
Configurable and dynamic source resolver.
With this package, you can configure custom imports in a "low level" way.
This package uses lambda-module-resolver
under the hood to handle the resolutions.
It's another package mantained by the AtSistemas development team, but we packaged it independently, so we could use its funcionality when performing SSR (server side rendering) so Babel could manage the custom rules as well.
Link: soon :)
How it works
- Define the rules
export default {
name,
pattern: source => pattern.test(source),
getPath ({
source,
filename
}) {
const featureRoot = RegExp(`.*(?!node_modules.*)${lookup}`).exec(filename)
const computedPath = source.replace(pattern, featureRoot[0])
return computedPath
}
}
- Add the resolver to the
resolve.plugins
section in the webpack config
You could also create a configured instance in another script (it would be the way to go)
export const resolve = {
plugins: [
new DynamicResolver(rules)
],
extensions: ['.js', '.jsx', '.css'],
modules: ['node_modules'],
alias: {
...
},
...
- Use your newly created rules in your codebase
// imports map component from a customized configured resolver
import { login } from '~this/actions'
// access an arbitrary container
import { LoginContainer } from '#Login'
Quickstart
wip (work in progress)
Docs
todo
Warning
The project has not implemented any error handling just yet, your rules should just work, or the compilation will fail suddenly.
License
MIT License
Team and Support
AtSistemas @2018
Create issues if you'd like to solve technical issues or propose new features, you'll be welcome! :)
Feel free to create PR or fork the project, it's open source! :)
todo