当前位置:网站首页>配置@路径简化路径处理
配置@路径简化路径处理
2022-08-11 05:17:00 【-加油】
1、安装修改 CRA 配置的包:yarn add -D @craco/craco
2、在项目根目录中创建 craco 的配置文件:craco.config.js,并在配置文件中配置路径别名
craco.config.js:
const path = require('path')
module.exports = {
// webpack 配置
webpack: {
// 配置别名
alias: {
// 约定:使用 @ 表示 src 文件所在路径
'@': path.resolve(__dirname, 'src')
}
}
}
3、修改 package.json 中的脚本命令。
package.json中的"scripts":全覆盖了
// 将 start/build/test 三个命令修改为 craco 方式
"scripts": {
"start": "craco start",
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject"
}
在代码中,就可以通过 @ 来表示 src 目录的绝对路径。
4、重启项目,让配置生效
npm start
或者
yarn start
@别名路径提示:能够让vscode识别@路径并给出路径提示
在项目根目录创建 jsconfig.json 配置文件
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@/*": ["src/*"]
}
}
}
边栏推荐
猜你喜欢
vscode插件
【CSDN21天学习挑战赛】第一天,配置环境外加实现mnist手写数字识别
vftpd本地可以连接,远程连接超时的解决
(3) Construction of a real-time performance monitoring platform (Grafana+Prometheus+Node_explorer+Jmeter)
【转载】如何理解数据集中【训练集】、【验证集】和【测试集】
软件测试风险识别
Flask framework to study: the debug and configuration items
【win10+cuda7.5+cudnn6.0安装caffe⑥】报错及处理方式
RK3399上的Tengine实践笔记
Flask framework learning: template rendering and Get, Post requests
随机推荐
Chapter 13 Class Inheritance-1
task02 fashion-mnist分类实战
Chapter 13 Class Inheritance
[转载]Verilog testbench总结
uniapp获取用户信息(登录及个人中心页面的实现)
C语言自定义类型——枚举类型讲解
【CSDN21天学习挑战赛】第一天,配置环境外加实现mnist手写数字识别
Install different versions of MinGW (g++/gcc) and the configuration of the corresponding clion editor under Win
【分享】一个免费语料库
pytorch矩阵运算问题
task04 Pytorch进阶训练技巧
[C language from elementary to advanced] Part 1 Initial C language (1)
【记录】没用知识点 - 智力题
【记录】innerHeight?clientHeight?offsetHeight?scrollTop?screenTop?.....一堆高度傻傻分不清
c pointer learning (2)
做款好喝的茶饮~
Redis - the solution to the failure of connecting to the redis server in linux using jedis
(1) Construction of a real-time performance monitoring platform (Grafana+Influxdb+Jmeter)
c指针学习(2)
08-JS对象、原型及原型链