Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $YECBGYFECGEAFWHA as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2

Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $BBWFDDBHHYHDXXAB as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2
sublime怎么配置js prettier自动格式化_Sublime集成Prettier实现JS代码自动格式化_创想鸟

sublime怎么配置js prettier自动格式化_Sublime集成Prettier实现JS代码自动格式化

首先安装Node.js和Prettier,再通过Package Control安装JsPrettier插件,配置prettier_cli_path、node_path及auto_format_on_save为true,确保保存时自动格式化JS代码。

sublime怎么配置js prettier自动格式化_sublime集成prettier实现js代码自动格式化

Sublime Text 虽然轻量,但通过插件可以很好地支持现代前端开发需求。要实现 JS 代码保存时自动用 Prettier 格式化,需结合 Node.js 环境与 Package Control 插件管理来配置。以下是完整步骤。

安装必要工具和插件

确保你的系统已安装以下内容:

Node.js:Prettier 是基于 Node 的工具,需先安装 Node.js(建议 v14 以上)。 Package Control:Sublime 的插件管理器,通常默认已安装。 Prettier 命令行工具:在终端执行:

npm install -g prettier

或项目内局部安装:

npm install --save-dev prettier

接着在 Sublime 中安装关键插件:

Ctrl+Shift+P 打开命令面板。 输入 Install Package,选择对应选项。 搜索并安装 JsPrettier(推荐名称为 “JsPrettier” 的插件,由 jdc0589 开发)。

配置 JsPrettier 插件

安装完成后,需要配置插件路径和格式化规则。

打开 Sublime 设置菜单:Preferences → Package Settings → JsPrettier → Settings。 修改 User 配置部分,例如指定 Prettier 可执行文件路径:

{  "prettier_cli_path": "/usr/local/bin/prettier",  "node_path": "/usr/local/bin/node",  "auto_format_on_save": true,  "auto_format_on_save_excludes": [    "*/node_modules/*",    "*/dist/*"  ]}

注意路径根据系统调整:

macOS/Linux:一般为 /usr/local/bin/prettierWindows:可能为 C:UsersYourNameAppDataRoamingnpmprettier.cmd,可用 where prettier 查找路径。

启用保存时自动格式化

关键配置项是 auto_format_on_save,设为 true 即可在保存文件时自动格式化。

如果你只想对 JS、JSX、Vue 等特定文件生效,可配合 Sublime 的语法检测机制使用。确保文件右下角显示 “JavaScript” 或 “Vue Component” 等正确语法类型。

集简云 集简云

软件集成平台,快速建立企业自动化与智能化

集简云 22 查看详情 集简云

如果只想部分项目开启,可在项目根目录添加 .prettierrc 文件定义规则,例如:

{  "semi": true,  "singleQuote": true,  "tabWidth": 2,  "trailingComma": "es5"}

这样 JsPrettier 会自动读取本地配置。

测试与调试

打开一个 JS 文件,写几行不规范的代码,如:

function test(){console.log('hello');}

保存文件(Ctrl+S),如果配置正确,代码会自动变成:

function test() {  console.log('hello');}

若未生效,检查:

终端运行 prettier --version 是否正常输出版本号。 Sublime 控制台(View → Show Console)是否有报错信息。 确认 JsPrettier 的配置路径无误。

基本上就这些。配置一次后,后续项目都能享受 Prettier 带来的代码整洁体验。

以上就是sublime怎么配置js prettier自动格式化_Sublime集成Prettier实现JS代码自动格式化的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/208340.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
Java中实现PDF文档并排对比及差异高亮显示:使用pdfcompare库
上一篇 2026年9月24日 12:55:13
鸣潮兑换码2025最新 永久有效兑换码合集
下一篇 2025年11月29日 12:15:02

相关推荐

发表回复

登录后才能评论
关注微信