typescript配置alias的详细步骤
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也可以参考如上步骤
相关推荐
changcongying 2020-11-02
changcongying 2020-10-30
苗疆三刀的随手记 2020-10-29
zouph000 2020-10-25
Jruing 2020-10-23
ctg 2020-10-14
PMJ0 2020-10-13
ChaITSimpleLove 2020-10-06
小飞侠V 2020-09-25
QiaoranC 2020-09-25
changcongying 2020-09-17
taizuduojie 2020-09-15
淼寒儿 2020-09-13
lyjava 2020-09-11
彤庆的技术 2020-09-02
锅哥 2020-08-27
zouph000 2020-08-03
Java编程语言学习 2020-07-29
shyoushine 2020-07-26