npm install babel-plugin-root-import --save-dev
or
yarn add babel-plugin-root-import --dev
使用.babelrc 或 babel.conf.js 两者只要配一个!
{ "plugins": [ ["babel-plugin-root-import"], { rootPathSuffix: "./src", rootPathPrefix: "@/" } ] }
module.exports = function(api) { api.cache(true); return { presets: ["babel-preset-expo", "mobx"], plugins: [ [ "babel-plugin-root-import", { rootPathSuffix: "./src", rootPathPrefix: "@/" } ] ] }; };
{ "compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["src/*"] } } }
参考文档:
https://www.npmjs.com/package/babel-plugin-root-import babel-plugin-root-import 插件文档
https://www.jianshu.com/p/6d2783f1ab51 tsconfig.json 配置列表
ReactNative typescript路径别名配置,vscode不识别@/youpath配置方法
原文:https://www.cnblogs.com/zjhblogs/p/12874175.html