vscode-livepreview/README.md

128 строки
7.7 KiB
Markdown
Исходник Постоянная ссылка Обычный вид История

# Live Preview - VS Code Extension 📡
2021-05-22 00:39:54 +03:00
2022-08-23 19:35:15 +03:00
⚠️ WARNING: This extension is still under development! ⚠️
2021-05-22 00:39:54 +03:00
2022-08-23 19:35:15 +03:00
An extension that hosts a local server for you to preview your web projects on!
2022-08-23 19:35:15 +03:00
This extension is most useful for projects where a server is not already created (e.g. not for apps using React, Angular, etc.). To work with these, feel free to run the `Simple Browser: Show` command that is already built-in with VS Code.
2021-05-28 02:58:24 +03:00
2021-06-22 01:06:29 +03:00
## Table of Contents
- [Features](#features)
- [Running the Extension](#running-the-extension)
- [FAQ](#faq)
2021-07-27 02:32:24 +03:00
- [Inspirations](#inspirations)
2021-06-22 01:06:29 +03:00
- [Issue Tracking](#issue-tracking)
2021-07-27 02:32:24 +03:00
- [Changelog](#changelog)
2021-06-22 01:06:29 +03:00
## Features
### HTML File Previewing
Preview your HTML files quickly by clicking the preview button in the top right corner of your editor or using the context menu.
2021-07-16 21:23:59 +03:00
![open-preview-btn](https://raw.githubusercontent.com/microsoft/vscode-livepreview/main/img/open-preview-btn.gif)
![open-context-menu](https://raw.githubusercontent.com/microsoft/vscode-livepreview/main/img/open-context-menu.gif)
2021-06-22 01:06:29 +03:00
### Embedded Preview
2021-07-26 20:35:39 +03:00
A preview is available in-editor for the files hosted by the server.
2021-06-22 19:29:37 +03:00
2021-07-16 21:23:59 +03:00
![browser-demo](https://raw.githubusercontent.com/microsoft/vscode-livepreview/main/img/browser-demo.gif)
2021-07-26 20:35:39 +03:00
The simple embedded browser features the following:
- Page history tracking
2021-07-26 20:35:39 +03:00
- URL bar for address-based navigation
- Expandable menu, allowing users to:
- Preview the current page in browser
- Perform a page search
2021-07-26 22:42:30 +03:00
- Tip: You can also use <kbd>CTRL</kbd>+<kbd>F</kbd> to open the find box and <kbd>Enter</kbd> to go to the next result
2021-07-26 20:35:39 +03:00
- Open the editor's webview DevTools
2021-07-26 20:49:56 +03:00
![find-demo](https://raw.githubusercontent.com/microsoft/vscode-livepreview/main/img/find-demo.gif)
2021-07-26 20:35:39 +03:00
2021-07-26 20:49:56 +03:00
![webview-devtools-demo](https://raw.githubusercontent.com/microsoft/vscode-livepreview/main/img/webview-devtools-demo.gif)
2021-06-22 01:06:29 +03:00
### Live Refreshing
See the changes as you make them. By default, changes appear as you make them in the editor. You can also change this in settings to refresh the preview on save or not at all.
2021-06-22 01:06:29 +03:00
2021-07-16 21:23:59 +03:00
![live-refresh](https://raw.githubusercontent.com/microsoft/vscode-livepreview/main/img/live-refresh.gif)
2022-07-17 13:07:44 +03:00
Individual pages can opt out of live refreshing by adding the `<body>` attribute `data-server-no-reload`.
2021-06-22 01:06:29 +03:00
### Persistent Server Task with Server Logging
If you're looking for a persistent server to run, you can run a `Live Preview` task, which also logs the server traffic. This can also be launched using the `Live Preview: Start Server Logging` command. You can click on the traffic to open the file location of the file returned by the server.
2021-06-22 19:29:37 +03:00
2021-07-16 21:23:59 +03:00
![task-demo](https://raw.githubusercontent.com/microsoft/vscode-livepreview/main/img/task-demo.gif)
![task-demo-2](https://raw.githubusercontent.com/microsoft/vscode-livepreview/main/img/task-demo-2.gif)
2021-06-22 19:29:37 +03:00
2021-07-19 20:00:42 +03:00
### External Browser Previewing
2021-06-22 19:29:37 +03:00
Although all of the images above use the embedded browser, you can also experience the same features in an external browser.
2021-07-16 21:23:59 +03:00
![external-window-demo](https://raw.githubusercontent.com/microsoft/vscode-livepreview/main/img/external-window-demo.gif)
2021-06-22 19:29:37 +03:00
You can edit the preview target in the extension settings.
2021-07-19 20:00:42 +03:00
### External Browser Debugging
The external browser preview also supports debugging via the built-in [js-debug](https://marketplace.visualstudio.com/items?itemName=ms-vscode.js-debug) extension and attaching to the [Edge Devtools Extension](https://marketplace.visualstudio.com/items?itemName=ms-edgedevtools.vscode-edge-devtools). This allows support for features such as setting breakpoints and inspecting elements.
2021-07-19 20:00:42 +03:00
2021-07-27 02:32:24 +03:00
Run `Live Preview: Show Debug Preview` in the command palette to get these debugging features.
2021-07-19 20:00:42 +03:00
![external-debug-demo](https://raw.githubusercontent.com/microsoft/vscode-livepreview/main/img/external-debug-demo.gif)
### Console Output Channel (For Embedded Preview)
For a simple view of the embedded preview's console messages, go to the `Output` tab and select `Embedded Live Preview Console` in the dropdown.
2021-07-16 21:23:59 +03:00
![console-demo](https://raw.githubusercontent.com/microsoft/vscode-livepreview/main/img/console-demo.gif)
2021-06-22 01:06:29 +03:00
### Workspace-less Previewing
No workspace? No problem! For a quick preview of your file, the server can also access files outside of your workspace to preview.
2021-07-16 21:23:59 +03:00
![no-workspace-preview](https://raw.githubusercontent.com/microsoft/vscode-livepreview/main/img/no-workspace-preview.gif)
2021-06-22 19:29:37 +03:00
2021-06-22 19:44:26 +03:00
Notes about workspace-less extension use:
2022-08-26 20:52:08 +03:00
- Files without a workspace will be served on its own server instance and will use its absolute path as the file path.
- Linked files for these pages may not be correct if they are relative to a specific root (e.g. a project root).
2021-06-30 19:29:01 +03:00
- Tasks do not work outside of a workspace, so a server will just launch in the background upon external preview when outside of a workspace. You can use the `Live Preview: Stop Server` command to kill the server in this case.
2021-06-29 01:54:18 +03:00
### Multi-root Support
2022-08-26 20:52:08 +03:00
Live Preview works cleanly with your multi-root workspaces! It will simply open an additional server for each root that you open a preview on.
![multi-root-demo](img/multi-root-demo.gif)
You can view the ports that are open for Live Preview by hovering the status bar indicator (usually located in the bottom-right corner of the window).
![multi-server-ports](img/server-status.png)
2021-06-29 02:00:10 +03:00
2021-06-22 01:06:29 +03:00
## Running the extension
2021-07-19 20:00:42 +03:00
You can install the extension [in the marketplace here](https://marketplace.visualstudio.com/items?itemName=ms-vscode.live-server). To contribute, see the [contributing page](https://github.com/microsoft/vscode-livepreview/blob/main/CONTRIBUTING.md).
2021-06-22 01:06:29 +03:00
## FAQ
**Q. What does the `"Previewing a file that is not a child of the server root. To see fully correct relative file links, please open a workspace at the project root or consider changing your server root settings for Live Preview."` message mean?**
2021-06-22 19:50:58 +03:00
2021-06-22 01:06:29 +03:00
A. Either:
- You have no workspace open and opened a preview.
- You opened a preview for a file that is not a part of your workspace(s).
- You have the `livePreview.serverRoot` setting set to a sub-folder in your workspace and your file is not a child of that subfolder.
2021-05-28 02:58:24 +03:00
Why does this happen?
2021-06-03 02:46:19 +03:00
The server is hosted from the root of the workspace that the user opens (or a subfolder of the workspace based on `livePreview.serverRoot`). Files outside of this can be previewed, but some file paths (such as a link to the root) may not go to the right place. **If you are working on a web project, it is advised that you open a workspace at the root of the project.**
2022-08-23 19:35:15 +03:00
**Q. I'm trying to use Live Preview in Codespaces and the embedded preview isn't working.**
2021-07-26 20:35:39 +03:00
A. Currently, you will need to manually navigate to the links host the forwarded port content before it works
In the area of the editor where the integrated terminal usually is, navigate to `Ports` and open the local addresses (usually at ports 3000 and 3001) in the browser. You can do this by using <kbd>CTRL</kbd>+<kbd>Click</kbd> on the URLs in the `Ports` menu.
2021-07-26 20:35:39 +03:00
Allow the browser to perform the necessary redirects, then close the windows. Re-open the preview window and it _should_ work now.
**Q. Why does my external browser preview look different than the preview in the embedded browser preview?**
A. Aspects such as styling might look different based on the browser cache of your external browser or any other client-side state. Try clearing your cache and restarting your browser.
2021-07-19 20:00:42 +03:00
## Inspirations
Special thanks to the following extensions for inspiring Live Preview! 💡
- [Live Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer)
- [Five Server](https://marketplace.visualstudio.com/items?itemName=yandeu.five-server)
2022-08-23 19:35:15 +03:00
2021-06-22 01:06:29 +03:00
## Issue Tracking
2021-07-26 20:35:39 +03:00
Please file issues against the [VS Code Live Preview repository](https://github.com/microsoft/vscode-livepreview/issues).
## Changelog
2021-09-08 12:46:15 +03:00
See the project's changelog [here](https://github.com/microsoft/vscode-livepreview/blob/main/CHANGELOG.md).