├── .gitignore ├── images ├── logo.png └── statusbar.png ├── messages.json ├── messages ├── install.txt ├── 1.0.2.txt └── 1.0.1.txt ├── LiveServer.sublime-settings ├── LiveServer.sublime-commands ├── LICENSE ├── plugin.py └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.html -------------------------------------------------------------------------------- /images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/molnarmark/sublime-live-server/HEAD/images/logo.png -------------------------------------------------------------------------------- /images/statusbar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/molnarmark/sublime-live-server/HEAD/images/statusbar.png -------------------------------------------------------------------------------- /messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "install": "messages/install.txt", 3 | "1.0.1": "messages/1.0.1.txt", 4 | "1.0.2": "messages/1.0.2.txt" 5 | } 6 | -------------------------------------------------------------------------------- /messages/install.txt: -------------------------------------------------------------------------------- 1 | Thank you for installing Live Server! 👋 2 | 3 | For usage instructions, head over to the GitHub repository of this project: 4 | https://github.com/molnarmark/sublime-live-server -------------------------------------------------------------------------------- /messages/1.0.2.txt: -------------------------------------------------------------------------------- 1 | 🌍 Live Server 1.0.2 2 | ==================== 3 | 4 | - Having a Sublime Text project open is not a requirement anymore for the server to work. 5 | 6 | Thank you for using Live Server. -------------------------------------------------------------------------------- /messages/1.0.1.txt: -------------------------------------------------------------------------------- 1 | 🌍 Live Server 1.0.1 2 | ==================== 3 | 4 | - Various fixes for Windows users 5 | 6 | ** For Windows users, its enough to set the 'node_executable_path' to 'node.exe' 7 | 8 | Thank you for using Live Server. -------------------------------------------------------------------------------- /LiveServer.sublime-settings: -------------------------------------------------------------------------------- 1 | // Note: These are just mappings to https://github.com/tapio/live-server#usage-from-command-line 2 | { 3 | "node_executable_path": "/usr/bin/node", 4 | "global_node_modules_path": "/usr/local/lib/node_modules", 5 | "port": 8080, 6 | "address": "localhost", 7 | "cors": true, 8 | "browser": "default", 9 | "nobrowser": false, 10 | "wait": 100 11 | } -------------------------------------------------------------------------------- /LiveServer.sublime-commands: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "Live Server: Start", 4 | "command": "live_server_start" 5 | }, 6 | { 7 | "caption": "Live Server: Stop", 8 | "command": "live_server_stop" 9 | }, 10 | { 11 | "caption": "Live Server: Open In Browser", 12 | "command": "live_server_open_in_browser" 13 | }, 14 | { 15 | "caption": "Preferences: Live Server Settings", 16 | "command": "edit_settings", 17 | "args": { 18 | "base_file": "${packages}/LiveServer/LiveServer.sublime-settings", 19 | "default": "// Live Server Settings\n{\n\t$0\n}\n" 20 | } 21 | } 22 | ] -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Mark Molnar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /plugin.py: -------------------------------------------------------------------------------- 1 | import sublime 2 | import sublime_plugin 3 | import subprocess 4 | import os, webbrowser 5 | 6 | SETTINGS_FILE = 'LiveServer.sublime-settings' 7 | SERVER_BINARY_PATH = '/live-server/live-server.js' 8 | PLUGIN_NODE_PATH = os.path.join( 9 | os.path.dirname(os.path.realpath(__file__)), 10 | SERVER_BINARY_PATH 11 | ) 12 | 13 | # handling windows 14 | if os.name == "nt": 15 | PLUGIN_NODE_PATH = SERVER_BINARY_PATH 16 | 17 | SERVER_PROCESS = None 18 | RUNNING_ON_PORT = None 19 | 20 | RUNNING_STATUS_MESSAGE = 'Live Server ✔️' 21 | STATUS_KEY = 'live_server_status' 22 | 23 | def plugin_unloaded(): 24 | if SERVER_PROCESS: 25 | SERVER_PROCESS.terminate() 26 | 27 | class LiveServerViewEventListener(sublime_plugin.ViewEventListener): 28 | def on_activated(self): 29 | if SERVER_PROCESS: 30 | self.view.set_status(STATUS_KEY, RUNNING_STATUS_MESSAGE) 31 | else: 32 | self.view.erase_status(STATUS_KEY) 33 | 34 | class LiveServerStartCommand(sublime_plugin.TextCommand): 35 | def run(self, edit): 36 | global SERVER_PROCESS, RUNNING_ON_PORT 37 | if SERVER_PROCESS: 38 | SERVER_PROCESS.terminate() 39 | 40 | settings = sublime.load_settings(SETTINGS_FILE) 41 | server_path = self.view.window().extract_variables()['file_path'] 42 | 43 | args = [ 44 | '--port={}'.format(settings.get('port')), 45 | '--address={}'.format(settings.get('address')), 46 | '--cors={}'.format(settings.get('cors')), 47 | '--wait={}'.format(settings.get('wait')), 48 | ] 49 | 50 | if (settings.get('browser') != 'default'): 51 | args.append('--browser={}'.format(settings.get('browser'))) 52 | 53 | if settings.get('nobrowser'): 54 | args.append('--no-browser') 55 | 56 | live_server_path = os.path.normpath(settings.get('global_node_modules_path') + PLUGIN_NODE_PATH) 57 | if os.name == 'nt': 58 | SERVER_PROCESS = subprocess.Popen( 59 | [settings.get('node_executable_path'), live_server_path, server_path] + args, 60 | stdout=subprocess.PIPE, 61 | stdin=subprocess.PIPE, 62 | stderr=subprocess.PIPE, 63 | env=os.environ.copy(), 64 | creationflags=0x08000000, 65 | startupinfo=None, 66 | ) 67 | else: 68 | SERVER_PROCESS = subprocess.Popen( 69 | [settings.get('node_executable_path'), live_server_path, server_path] + args, 70 | stdout=subprocess.PIPE, 71 | stdin=subprocess.PIPE, 72 | stderr=subprocess.PIPE, 73 | env=os.environ.copy(), 74 | startupinfo=None, 75 | ) 76 | 77 | RUNNING_ON_PORT = settings.get('port') 78 | 79 | self.view.window().status_message('🎉 Live Server running on {}.'.format(settings.get('port'))) 80 | self.view.set_status(STATUS_KEY, RUNNING_STATUS_MESSAGE) 81 | 82 | class LiveServerStopCommand(sublime_plugin.TextCommand): 83 | def run(self, edit): 84 | global SERVER_PROCESS 85 | SERVER_PROCESS.terminate() 86 | SERVER_PROCESS = None 87 | self.view.window().status_message('❌ Live Server stopped.') 88 | self.view.erase_status(STATUS_KEY) 89 | 90 | class LiveServerOpenInBrowserCommand(sublime_plugin.TextCommand): 91 | def run(self, edit): 92 | if SERVER_PROCESS: 93 | self.view.window().status_message('📖 Opening Live Server..') 94 | webbrowser.open('http://localhost:{}'.format(RUNNING_ON_PORT)) 95 | else: 96 | self.view.window().status_message('❌ Live Server isn\'t running. Nothing to open.') 97 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 |

Launch a Development Server directly from Sublime Text!

4 |

5 | 6 | ## 📋 Introduction 7 | 8 | This package integrates the **[Live Server](https://www.npmjs.com/package/live-server)** Node package, giving the ability to launch a local development server to serve content directly from Sublime Text. 9 | 10 | #### 💡 About Live Server: 11 | 12 | **[Live Server](https://www.npmjs.com/package/live-server)** is Node.js tool that spins up a local development server in the given directory. 13 | 14 | It features live browser reloading, which simply means that your browser will automatically refresh the page when any change is made to your HTML & CSS files. 15 | 16 | Useful for static sites, SPAs, and general HTML/CSS fiddling. 17 | 18 | ## ❗Prerequisites 19 | 20 | You need the following software installed to use **Live Server**. 21 | 22 | - [**`Node.js`**](https://nodejs.org/) 23 | - [**`npm`**](https://npmjs.com) or [**`Yarn`**](https://yarnpkg.com) 24 | - [**`Live Server`**](https://www.npmjs.com/package/live-server) installed globally 25 | 26 | To install Live Server globally using **`npm`**, run: 27 | 28 | ```sh 29 | npm install -g live-server 30 | ``` 31 | 32 | To install Live Server globally using **`Yarn`**, run: 33 | 34 | ```sh 35 | yarn global add live-server 36 | ``` 37 | 38 | ## 🌀 Installation 39 | 40 | #### Package Control 41 | 42 | This package is available in Package Control under the name **LiveServer**. 43 | 44 | #### As a Repository 45 | 46 | - Bring up the Command Palette (**Ctrl** + **Shift** + **p**) 47 | - Select **`Package Control: Add Repository`** 48 | - Paste https://github.com/molnarmark/sublime-live-server 49 | - Press Enter 50 | - For Windows machine, you need to change the package's config settings, check below [🔨 Settings](#-settings) 51 | 52 | ## ❓ Usage 53 | 54 | This package exposes 3 commands that can be used directly via the Command Palette, or bound to keys. These are: 55 | 56 | **`Live Server: Start`** 57 | 58 | - Maps to `live_server_start` 59 | 60 | **`Live Server: Stop`** 61 | 62 | - Maps to `live_server_stop` 63 | 64 | **`Live Server: Open In Browser`** 65 | 66 | - Maps to `live_server_open_in_browser` 67 | 68 | Status bar messages with indicator emojis are implemented into the package, displaying information in cases such as: 69 | 70 | - 🎉 Live Server running 71 | - ❌ Live Server stopped 72 | - ✔️ Live Server status 73 | 74 | When the development server is running, a status message will be shown in the status bar indicating that the server is running. 75 | This is shared across all views in the opened instance. 76 | 77 |

78 | 79 |

80 | 81 | ## 🔨 Settings 82 | 83 | To change your settings, bring up the Command Palette and select: **`Preferences: Live Server Settings`** 84 | 85 | The default settings for linux are the following: 86 | 87 | ```js 88 | // Note: These are just mappings to https://github.com/tapio/live-server#usage-from-command-line 89 | { 90 | "node_executable_path": "/usr/bin/node", 91 | "global_node_modules_path": "/usr/local/lib/node_modules", 92 | "port": 8080, 93 | "address": "localhost", 94 | "cors": true, 95 | "browser": "default", 96 | "nobrowser": false, 97 | "wait": 100 98 | } 99 | ``` 100 | 101 | #### **`node_executable_path`** 102 | 103 | - Path to the Node runtime executable. You can run **`whereis node`** in your terminal to find this. 104 | - In _Windows Command Prompt_, run **`where node`** 105 | - ##### **`default value: /usr/bin/node`** 106 | 107 | #### **`global_node_modules_path`** 108 | 109 | - Path to the default **node_modules** directory. You can run **`npm root -g`** or **`yarn global bin`** in your terminal to find this. 110 | - ##### **`default value: /usr/local/lib/node_modules`** 111 | 112 | #### **`port`** 113 | 114 | - The default port for the server. 115 | - ##### **`default: 8080`** 116 | 117 | #### **`address`** 118 | 119 | - Host address. This should always be either localhost or 127.0.0.1. 120 | - ##### **`default: localhost`** 121 | 122 | #### **`cors`** 123 | 124 | - Enables CORS for any origin. 125 | - ##### **`default: true`** 126 | 127 | #### **`browser`** 128 | 129 | - Specifies which browser to use. 130 | - Valid values are: 131 | 132 | - **`default`** 133 | - **`google-chrome`** 134 | - **`firefox`** 135 | 136 | - ##### **`default: default`** 137 | 138 | #### **`nobrowser`** 139 | 140 | - By setting this to true, the browser will not open the server by default 141 | - ##### **`default: false`** 142 | 143 | #### **`wait`** 144 | 145 | - Wait this amount of milliseconds before reloading the page after a change 146 | - ##### **`default: 100`** 147 | 148 | ## 🔖 Credits 149 | 150 | - This package wouldn't exist without the amazing [**`Node`**](https://nodejs.org/) package also called **[Live Server](https://www.npmjs.com/package/live-server)** by **[Tapio Vierros](https://github.com/tapio)**. 151 | --------------------------------------------------------------------------------