我有一个monorepo:
domain/
entities/
account.ts
...
mobile/
src/
app.ts
node_modules/
package.json
babel.config.js
我想设置一个别名,以便app.ts
可以简单地调用:
import { Account } from 'domain/entities/account'
代替
import { Account } from '../../../domain/entities/account'
我试着这样做:
const path = require('path')
module.exports = (api) => {
api.cache(true)
return {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
['module:react-native-dotenv', {
moduleName: 'react-native-dotenv'
}],
[
'module-resolver',
{
extensions: [
'.js',
'.jsx',
'.ts',
'.tsx'
],
alias: {
domain: path.resolve(__dirname, '../domain')
}
}
]
]
}
}
但不幸的是,它不起作用。它抛出:
Error: Unable to resolve module /home/kibe/work/iros-customer-frontend/domain/entities/account from ...
None of these files exist:
* ../domain/entities/account(.js|.jsx|.ts|.tsx)
如何从主目录外部导入内容?