babel-plugin-module-resolver icon indicating copy to clipboard operation
babel-plugin-module-resolver copied to clipboard

Allow non-module resolves

Open MrQubo opened this issue 5 years ago • 0 comments

This will allow resolving paths that aren't necessarily pointing to modules.

This can be achieved by adding isModulePath option to transform function. It makes sense to add this option there because whether the path should be interpreted as a path to the module or not depends on the calling function.

My use case is for configuring views and static directory for express.js. With this PR I can do something like this:

app.use(express.static(resolvePath('$res/public/')));

Where resolvePath is just an identity function (see DOCS.md#usage-with-proxyquire) and is configured via transformFunctions options like this:

transformFunctions: [
  ['resolvePath', { isModulePath: false }],
],

In this example, it is also possible to add express.static to transformFunctions list.

MrQubo avatar Mar 31 '20 16:03 MrQubo