ruanhongbiao 2020-08-16
1 安装依赖
npm install --save-dev babel-plugin-module-resolver # yarn add babel-plugin-module-resolver --dev
根目录新增.babelrc文件
参考以下内容按您项目中的需要去修改
{ "presets": ["next/babel"], "plugins": [ [ "module-resolver", { "alias": { "@/actions": "./actions", "@/components": "./components", "@/constants": "./constants", "@/pages": "./pages", "@/public": "./public", "@/reducers": "./reducers", "@/utils": "./utils" } } ] ] }
修改tsconfig.json文件
{ "compilerOptions": { "baseUrl": "./", "paths": { "@components/*": ["./components/*"], "@pages/*": ["./pages/*"], "@public/*": ["./public/*"] } } }
注意"baseUrl": "./",不能省去,否则ts报Option 'paths' cannot be used without specifying '--baseUrl' option.错误
next.js中配置alias也可以参考如上步骤
运算符用于执行程序代码运算,会针对一个以上操作数项目来进行运算。以上实例中 7、5 和 12 是操作数。关系运算符用于计算结果是否为 true 或者 false。逻辑运算符用于测定变量或值之间的逻辑。