当前位置:网站首页>配置@路径简化路径处理
配置@路径简化路径处理
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/*"]
}
}
}
边栏推荐
- 2021研究生数学建模D题,BP神经网络和卷积神经网络解题代码(基于pytorch)
- 表单input控件数据双向绑定
- 【记录】innerHeight?clientHeight?offsetHeight?scrollTop?screenTop?.....一堆高度傻傻分不清
- LeetCode1166.设计文件系统
- RK3399上的Tengine实践笔记
- 第9章 内存模型和名称空间
- C language file operation - detailed explanation of data file type, file judgment, and file buffer
- 第4章 复合类型-1
- pytorch矩阵运算问题
- bootstarp作业一:制作分页器
猜你喜欢
随机推荐
Chapter 13 Class Inheritance
PHP提高并发能力有哪些方案
【记录】TypeScript
【翻译】博客游戏项目Q1K3 – 制作
Markdown 常用到的一些编写技巧
设计三级联动
第4章 复合类型-1
2021研究生数学建模D题,BP神经网络和卷积神经网络解题代码(基于pytorch)
数组的用法
C language file operation - detailed explanation of data file type, file judgment, and file buffer
自制病毒——整蛊
QT circle函数(图片标注)
C语言——动态内存分配常见的错误案例
ES11新增数据类型BigInt大整型
Chapter 4 Composite Types-1
【网站小白】Hibernate插入数据成功,不报错,但是数据库中没有值
pytorch安装笔记——Pytorch在conda+CUDA10.2环境安装task01
bootstarp作业一:制作分页器
(2) Construction of a real-time performance monitoring platform (Grafana+Prometheus+Jmeter)
开炮,开炮