module-name-mapper
v1.0.3
Published
Convert your TSConfig paths to the most common module name mappers.
Downloads
45
Maintainers
Readme
Module Name Mapper
Convert your tsconfig.json
paths to the most common module name mappers.
Installation
Installing module-name-mapper
only takes a single command and you're ready to roll:
# with npm
npm install module-name-mapper --save-dev
# with yarn
yarn add module-name-mapper -D
Usage
import { getBabelModuleNameMapper, getJestModuleNameMapper } from 'module-name-mapper';
Supported Plugins
- Babel: Module Resolver
- Jest: ModuleNameMapper
Babel
// babel.config.js
const { getBabelModuleNameMapper } = require('module-name-mapper')
module.exports = function(api) {
api.cache(true);
return {
...
plugins: [
[
require.resolve('babel-plugin-module-resolver'),
getBabelModuleNameMapper('./tsconfig.json'),
],
],
...
}
}
Jest
// jest.config.ts
import { getJestModuleNameMapper } from 'module-name-mapper'
module.exports = {
...
rootDir: getJestModuleNameMapper('./tsconfig.json').rootDir,
moduleNameMapper: getJestModuleNameMapper('./tsconfig.json').moduleNameMapper,
...
}