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

Viewed 809

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

3 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.

You can use JSCustom package. https://github.com/Thom1729/Sublime-JS-Custom

Open the command palette

Win/Linux: ctrl+shift+p, Mac: cmd+shift+p

Type Install Package Control, press enter and search JSCustom

After installing JSCustom

choose: Preferences → Package Settings → JS Custom → Rebuild Syntaxes

Now reopen sublimeText. It will open any js file as JSX

Related