-
Notifications
You must be signed in to change notification settings - Fork 487
Allow moduleNameMapper config override
#303
Allow moduleNameMapper config override
#303
Conversation
|
Any news on this? Any plan to merge this PR to have |
| 'coverageReporters', | ||
| 'coverageThreshold', | ||
| 'snapshotSerializers', | ||
| 'moduleNameMapper', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- This should be listed in the corresponding README to be adjustable. Just recognized that the original section on CRA (https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#configuration) is absent here... However, this field (and potentially the section) should be listed there, including the example usage and a note on how this relates to entries in the
tsconfig.json. - I'm still thinking about the default value used on this field,
'^react-native$': 'react-native-web'. It should either be noted that it has to be provided manually in case of overriding this key, or that entry should be merged automatically. Suppose the first way might be preferable.
|
I'm very sorry for the late response, I was quite busy lately and also attempted to figure out why the travis build began to fail shortly after it was fixed for the master branch ... Comments are attached on the review. |
|
@DorianGrey No problem, I'll integrate the suggested changes next week 🙂 |
|
@DorianGrey added the section to the readme as suggested 🙂 |
|
LGTM, thanks! (Note: I'll ignore the failing CI for the moment - that |
|
Nice! When will this be released to npm? |
|
I'm still waiting for a reaction on #314 to figure out if pinning the |
This reverts commit e17362e.
This patch will allow path mapping to be fully supported, by allowing
moduleNameMapperto be configured.Issue
Currently, you can add paths to your
tsconfigand the app will run fine. Butjest/ts-jestdoes not use the configuration from yourtsconfig. Configuring themoduleNameMapperwill solve this. Sadly, the property is not "supported" and tests can not be run if the configuration is set.Example usage:
Changing the following files will allow you to import modules from the
srcfolder, by prefixing the import path with a tilde. E.g. a component living insrc/components/Buttoncan always be imported via~/components/Button. No../../../anymore!tsconfig.json{ "compilerOptions": { ... + "baseUrl": ".", + "paths": { + "~/*": ["src/*"] + } },package.json{ ... "jest": { ... + "moduleNameMapper": { + "^~/(.*)$": "<rootDir>/src/$1" + } }, }Changes:
baseUrlsotsconfig-paths-webpack-pluginwill not warn that it is missing (Fixed problem with tsconfig.json baseUrl and paths #223)moduleNameMapper(Support for TypeScripts 'paths' option #203)Allow overriding the
moduleNameMapperconfiguration is the pragmatic approach. If you're using absolute paths + react-native you would have to re-add the mapping.