emersonthis
emersonthis

Reputation: 33368

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

Upvotes: 4

Views: 3068

Answers (3)

Lesther
Lesther

Reputation: 545

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.

Upvotes: 9

MRMillon
MRMillon

Reputation: 43

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

Upvotes: 2

emersonthis
emersonthis

Reputation: 33368

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.

Upvotes: 2

Related Questions