elksie5000
elksie5000

Reputation: 7752

How to use Chrome as build in Sublime Text

I'm trying to set up Chrome as a build system in Sublime Text on MacOs.

Tried using the New build menu option and plugged in:

{
"/Applications/Google Chrome.app": "Chrome"
}

It appears in list after I restart as build option but doesn't work. Any ideas?

Upvotes: 0

Views: 1662

Answers (1)

MattDMo
MattDMo

Reputation: 102852

For reference, the build system documentation has lots of examples if you want to add more functionality. However, for now, we'll just make a simple build system with one command - open the current file in Chrome.

Each build system needs to have a "cmd" key - the command you want to run - and optionally a "selector" key - a rule for selecting which types of files you want to run. For now, we'll just assume you only want to run HTML files. Select Tools → Build System → New Build System… and replace the contens with this:

{
    "cmd": ["/Applications/Google Chrome.app", "$file"],
    "selector": "text.html"
}

Next, hit Save and save the file in the suggested folder with a name like Chrome.sublime-build. You don't need to restart for it to be visible in the Build System menu.

Now, when you want to view an HTML file in Chrome, you'll first select Tools → Build System → Chrome, then hit B to actually run the build. Chrome will stay selected as the current build system, so if you want to build again all you have to do is hit B.

If you do any work on Windows or Linux, the build command shortcut is CtrlB.

Upvotes: 2

Related Questions