当前位置:网站首页>配置@路径简化路径处理
配置@路径简化路径处理
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/*"]
}
}
}
边栏推荐
- QT circle函数(图片标注)
- EOF, feof function, ferror function in C language
- Flask framework learning: template inheritance
- ClionIDE compiles by specifying the compiler
- (2) Construction of a real-time performance monitoring platform (Grafana+Prometheus+Jmeter)
- 【网站小白】Hibernate插入数据成功,不报错,但是数据库中没有值
- 【记录】innerHeight?clientHeight?offsetHeight?scrollTop?screenTop?.....一堆高度傻傻分不清
- 【翻译】博客游戏项目Q1K3 – 制作
- 08-JS对象、原型及原型链
- Introduction of several ways to initialize two-dimensional arrays in C language (private way to initialize large arrays)
猜你喜欢
随机推荐
RK3399上的Tengine实践笔记
旅游住宿酒店14页
Some Error in Visual Studio solution
字符与字符串
uniapp获取用户信息(登录及个人中心页面的实现)
Django--20 implements Redis support, context, and interaction of context and interface
Summary: Cross Validation
设计三级联动
Some writing skills commonly used in Markdown
Chapter 13 Class Inheritance
C语言——文件操作详解(1)
普林斯顿概率论读本读书笔记(阅读中......)
(2) Docker installs Redis in practice (persistent AOF and RDB snapshots)
第4章 复合类型-1
Object.keys
【win10+cuda7.5+cudnn6.0安装caffe③】编译及测试caffe
CSDN 社区内容创作规范
Markdown 常用到的一些编写技巧
【备忘】于仕琪的libfacedetection相关
Qt 字符串截取 查找字符串