Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Sublime 3 open .js files with JSX syntax

I'm using Sublime 3 on MacOS 10.15.7 and I'm working on a React project.

I have a package installed for JSX syntax highlighting, and it works fine if I manually set it after opening the file. By default, it starts with JavaScript highlighting every time I open the files because my component files have .js extensions. (There are reasons for this.) Is there a way for me to configure Sublime to open these project files with JSX highlighting automatically? If it helps, I also use editorconfig.

NOTE: I don't want to force Sublime to globally open ANY js file as JSX because that will cause the reverse problem with all my Node.js / JavaScript projects. I need a solution that is project-specific.

Thanks in advance!

Sort of related to: Syntax specific settings in sublime-project settings file

like image 630
emersonthis Avatar asked Oct 28 '25 10:10

emersonthis


2 Answers

Just go to:

View > Syntax > Open all with current extension as ... > JavaScript >

Then select JSX. It will open all JS as JSX, you can confirm it when you see the type of the file at the bottom right of the sublime window.

like image 164
Lesther Avatar answered Oct 30 '25 09:10

Lesther


With further digging, I found this package which appears to enable this feature: https://github.com/reywood/sublime-project-specific-syntax

But I'd prefer a native solution, if possible.

like image 38
emersonthis Avatar answered Oct 30 '25 10:10

emersonthis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!