利用addWebpackAlias配置路径
const path = require('path')
const { addDecoratorsLegacy, override, addWebpackAlias } = require('customize-cra')
// 追加上一个装饰器
module.exports = override(
addDecoratorsLegacy(),
addWebpackAlias({
'@': path.resolve('src')
}),
customConfig()
)
自定义配置
const path = require('path')
const customConfig = () => config => {
config.resolve.alias['@'] = path.resolve('src')
return config
}
module.exports = override(
addDecoratorsLegacy(),
customConfig(),
// 按需要加载css,无用的css在打包时,不会打包到项目中
fixBabelImports('import', { libraryName: "antd-mobile", style: "css" })
)
配置路径别名这样的话就会短一些
jsconfig.json
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@/*": ["src/*"]
}
}
}