uni-app小程序开发-HBuilderX配置

前言

开发uni-app时最好用的IDE还是HBuilder X,尽管它有很多小问题。

开发Uni-App最好的IDE

https://www.dcloud.io/hbuilderx.html

界面字体太小

界面字体太小的解决方法

image-20240725222928040

格式化

默认的格式化插件不好用

scss/less文件默认不会被格式化,并且JSON格式化的也不太好。

需要我们安装格式化插件Prettier

https://ext.dcloud.net.cn/plugin?id=2025

工具 => 设置 => 插件配置 => 自定义prettier格式化规则

image-20240730232616760

添加如下配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Prettier配置文档:https://prettier.io/docs/en/options.html
module.exports = {
printWidth: 80,
tabWidth: 4,
useTabs: false,
semi: true,
singleQuote: true,
quoteProps: "as-needed",
jsxSingleQuote: false,
trailingComma: "none",
bracketSpacing: true,
bracketSameLine: false,
arrowParens: "always",
proseWrap: "preserve",
htmlWhitespaceSensitivity: "ignore",
vueIndentScriptAndStyle: false,
endOfLine: "lf",
embeddedLanguageFormatting: "auto",
singleAttributePerLine: false,
//自定义文件后缀对应的parser
parsers: {
".nvue": "vue",
".ux": "vue",
".uvue": "vue",
".uts": "typescript"
}
}

主要是修改

1
printWidth: 80,

建议这个值和编辑器配置 => 长行指示竖线显示在第几列的值保持一致。

如果想属性都换行可以设置

1
singleAttributePerLine: true