美文网首页前端修仙之路
creat-react-app ts 配置路径别名 config

creat-react-app ts 配置路径别名 config

作者: 橘子花儿橙味甜 | 来源:发表于2020-04-20 15:11 被阅读0次

官方文档里面配置是

const { override, fixBabelImports, addLessLoader, addWebpackPlugin, addWebpackAlias } = require('customize-cra')
const path = require('path')
module.exports = override(
    fixBabelImports('import', {
        libraryName: 'antd',
        libraryDirectory: 'es',
        style: true,
    }),
    addWebpackAlias({
        ['@']: path.resolve(__dirname, './src'),
    })
})

然后用的tsx,一直报错
Cannot find module '@'


image.png

头都大了
搞了很久,发现应该是我TS的基础有问题,因为刚接触
在根目录下新建 >paths.json

{
    "compilerOptions": {
        "baseUrl": "src",
        "paths": {
            "@/*": [
                "*"
            ]
        }
    }
}

在tsconfig.json 加入

"extends": "./paths.json",

现在启动服务终于不报错了

相关文章

网友评论

    本文标题:creat-react-app ts 配置路径别名 config

    本文链接:https://www.haomeiwen.com/subject/ajldihtx.html