
Sử dụng Alias imports
npx react-native@latest init PROJECT_NAME
//Thay thế PROJECT_NAME thành tên dự án của bạn babel.config.jsmodule.exports = {
presets: ['module:@react-native/babel-preset'],
// - Add this -
plugins: [
...
[
'module-resolver',
{
root: ['.'],
alias: {
// This has to be mirrored in tsconfig.json
'^@/(.+)': './src/\\1',
},
},
],
],
// - Add this -
};tsconfig.json{
"extends": "@react-native/typescript-config/tsconfig.json",
// - Add this -
"compilerOptions": {
"strict": true,
"baseUrl": ".",
"paths": {
//We will have to add the same thing in babel.config.js
"@/*": ["src/*"]
}
}
// - Add this -
}.hintrc{
"extends": ["development"],
"hints": {
"typescript-config/is-valid": "off"
}
}yarn add --dev babel-plugin-module-resolvernpx pod-install iosShare this article
Share: