Visual Studio Code - 在保存时编译 Javascript [英] Visual Studio Code - compile Javascript on save

查看:43
本文介绍了Visual Studio Code - 在保存时编译 Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视频教程的导师使用他的 VS Code 编辑器在保存时编译 javascript/react.我的没有.如何配置 VS Code 来执行此操作?

The tutor of my video tutorial compiles javascript/react on save with his VS Code editor. Mine dont. How can I config VS Code to do this?

备注:我找到了打字稿Visual Studio Code - 保存时编译"的解决方案,但建议的解决方案对我不起作用.

Remark: I find solution for typescript "Visual Studio Code - compile on save", but suggested solution does not work for me.

@已添加信息:该项目是使用 create.react-app 创建的.npm start 打开 chrome,然后编译错误会显示在 Chrome 的 DEV-Console 中,正如 Shishani 所指出的.我的导师在 VS Code 终端控制台上编译了代码.这提供了在我转到 webbrowser 之前快速检查代码编译,检查那里的错误,在我看来,它的长调用堆栈更令人生畏.

@added information: the project is created with create.react-app. npm start opens chrome, and compilation errors are then shown in Chrome's DEV-Console, as noted by Shishani . My tutor has the code compiled on VS Code Terminal console. This offers a quick check of the code compilation before I go to webbrowser, to check for errors there, which seems to me much more intimidating with it's long callstacks.

推荐答案

如果你用 create-react-app 创建你的 React 项目,然后用 npm start 启动它>,它会在保存时自动编译.此外,如果它不是 React 项目,而只是 JS/HTML/CSS,您可以使用Live Server"打开您的项目.VSCode 中的扩展,并且每次在 VSCode 工作区中保存文件时它都会更新您的页面.

If you create your React project with create-react-app, and then start it with npm start, it compiles automatically on save. Also, if it's not a React project, but just JS/HTML/CSS, you can open your project with the "Live Server" extension in VSCode, and it will update your page every time you save a file in your VSCode workspace.

您甚至可以像我一样使用 VSCode 中的 AutoSave: afterDelay 设置启用持续自动保存(如果您敢的话),然后将保存延迟设置为一个非常小的数字(我的是 2 毫秒),因此您甚至不需要再点击保存(转到 File>Preferences>Settings>[SearchAuto Save"]).

You can even do like I do, and enable constant autosave, with the AutoSave: afterDelay setting in VSCode (if you dare), and then set the save delay to a super small number (mine is 2ms) so you don't even need to hit save anymore (go to File>Preferences>Settings>[Search "Auto Save"]).

这篇关于Visual Studio Code - 在保存时编译 Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆