-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update the extension for seamless Vue integration
- Loading branch information
1 parent
73c1b40
commit b361231
Showing
30 changed files
with
1,120 additions
and
2,095 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,18 @@ | ||
{ | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 6, | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"rules": { | ||
"@typescript-eslint/naming-convention": [ | ||
"warn", | ||
{ | ||
"selector": "import", | ||
"format": [ "camelCase", "PascalCase" ] | ||
} | ||
], | ||
"@typescript-eslint/semi": "warn", | ||
"curly": "warn", | ||
"eqeqeq": "warn", | ||
"no-throw-literal": "warn", | ||
"semi": "off" | ||
}, | ||
"ignorePatterns": [ | ||
"out", | ||
"dist", | ||
"**/*.d.ts" | ||
] | ||
} | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 6, | ||
"sourceType": "module" | ||
}, | ||
"plugins": ["@typescript-eslint"], | ||
"rules": { | ||
"@typescript-eslint/naming-convention": "warn", | ||
"@typescript-eslint/semi": "warn", | ||
"curly": "warn", | ||
"eqeqeq": "warn", | ||
"no-throw-literal": "warn", | ||
"semi": "off" | ||
}, | ||
"ignorePatterns": ["webview-ui/**"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
/dist | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"printWidth": 100, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"semi": true, | ||
"singleQuote": false, | ||
"quoteProps": "consistent", | ||
"jsxSingleQuote": false, | ||
"trailingComma": "es5", | ||
"bracketSpacing": true, | ||
"jsxBracketSameLine": true, | ||
"arrowParens": "always" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,35 @@ | ||
# This file contains all the files/directories that should | ||
# be ignored (i.e. not included) in the final packaged extension. | ||
|
||
# Ignore extension configs | ||
.vscode/** | ||
|
||
# Ignore test files | ||
.vscode-test/** | ||
out/test/** | ||
|
||
# Ignore source code | ||
src/** | ||
.gitignore | ||
|
||
# Ignore all webview-ui files except the build directory | ||
webview-ui/src/** | ||
webview-ui/public/** | ||
webview-ui/scripts/** | ||
webview-ui/index.html | ||
webview-ui/README.md | ||
webview-ui/package.json | ||
webview-ui/package-lock.json | ||
webview-ui/node_modules/** | ||
|
||
# Ignore Misc | ||
.yarnrc | ||
vsc-extension-quickstart.md | ||
**/.gitignore | ||
**/tsconfig.json | ||
**/vite.config.ts | ||
**/.eslintrc.json | ||
**/*.map | ||
**/*.ts | ||
**/.vscode-test.* | ||
**/*.js.map | ||
|
||
# Ignore OS files | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Extension commands | ||
|
||
A quick run down of some of the important commands that can be run when at the root of the project. | ||
|
||
``` | ||
npm run install:all Install package dependencies for both the extension and Vue webview source code. | ||
npm run start:webview Runs the Vue webview source code in development mode. Open http://localhost:3000 to view it in the browser. | ||
npm run build:webview Build Vue webview source code. Must be executed before compiling or running the extension. | ||
npm run compile Compile VS Code extension. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Extension development cycle | ||
|
||
The intended development cycle of this Vue-based webview extension is slightly different than that of other VS Code extensions. | ||
|
||
Due to the fact that the `webview-ui` directory holds a self-contained Vue application we get to take advantage of some of the perks that that enables. In particular, | ||
|
||
- UI development and iteration cycles can happen much more quickly by using Vite | ||
- Dependency management and project configuration is hugely simplified | ||
|
||
## UI development cycle | ||
|
||
Since we can take advantage of the much faster Vite dev server, it is encouraged to begin developing webview UI by running the `npm run start:webview` command and then editing the code in the `webview-ui/src` directory. | ||
|
||
_Tip: Open the command palette and run the `Simple Browser` command and fill in `http://localhost:3000/` when prompted. This will open a simple browser environment right inside VS Code._ | ||
|
||
### Message passing | ||
|
||
If you need to implement message passing between the webview context and extension context via the VS Code API, a helpful utility is provided in the `webview-ui/src/utilities/vscode.ts` file. | ||
|
||
This file contains a utility wrapper around the `acquireVsCodeApi()` function, which enables message passing and state management between the webview and extension contexts. | ||
|
||
This utility also enables webview code to be run in the Vite dev server by using native web browser features that mock the functionality enabled by acquireVsCodeApi. This means you can keep building your webview UI with the Vite dev server even when using the VS Code API. | ||
|
||
### Move to traditional extension development | ||
|
||
Once you're ready to start building other parts of your extension, simply shift to a development model where you run the `npm run build:webview` command as you make changes, press `F5` to compile your extension and open a new Extension Development Host window. Inside the host window, open the command palette (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and type `Hello World (Vue): Show`. | ||
|
||
## Dependency management and project configuration | ||
|
||
As mentioned above, the `webview-ui` directory holds a self-contained and isolated Vue application meaning you can (for the most part) treat the development of your webview UI in the same way you would treat the development of a regular Vue application. | ||
|
||
To install webview-specific dependencies simply navigate (i.e. `cd`) into the `webview-ui` directory and install any packages you need or set up any Vue specific configurations you want. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Extension structure | ||
|
||
This section provides a quick introduction into how this sample extension is organized and structured. | ||
|
||
The two most important directories to take note of are the following: | ||
|
||
- `src`: Contains all of the extension source code | ||
- `webview-ui`: Contains all of the webview UI source code | ||
|
||
## `src` directory | ||
|
||
The `src` directory contains all of the extension-related source code and can be thought of as containing the "backend" code/logic for the entire extension. Inside of this directory you'll find the: | ||
|
||
- `panels` directory | ||
- `utilities` directory | ||
- `extension.ts` file | ||
|
||
The `panels` directory contains all of the webview-related code that will be executed within the extension context. It can be thought of as the place where all of the "backend" code for each webview panel is contained. | ||
|
||
This directory will typically contain individual TypeScript or JavaScript files that contain a class which manages the state and behavior of a given webview panel. Each class is usually in charge of: | ||
|
||
- Creating and rendering the webview panel | ||
- Properly cleaning up and disposing of webview resources when the panel is closed | ||
- Setting message listeners so data can be passed between the webview and extension | ||
- Setting the initial HTML markdown of the webview panel | ||
- Other custom logic and behavior related to webview panel management | ||
|
||
As the name might suggest, the `utilties` directory contains all of the extension utility functions that make setting up and managing an extension easier. In this case, it contains `getUri.ts` which contains a helper function which will get the webview URI of a given file or resource. | ||
|
||
Finally, `extension.ts` is where all the logic for activating and deactiving the extension usually live. This is also the place where extension commands are registered. | ||
|
||
## `webview-ui` directory | ||
|
||
The `webview-ui` directory contains all of the Vue-based webview source code and can be thought of as containing the "frontend" code/logic for the extension webview. | ||
|
||
This directory is special because it contains a full-blown Vue application which was created using the `create-vue` scaffolding tool. As a result, `webview-ui` contains its own `package.json`, `node_modules`, `tsconfig.json`, and so on––separate from the `hello-world` extension in the root directory. | ||
|
||
This strays a bit from other extension structures, in that you'll usually find the extension and webview dependencies, configurations, and source code more closely integrated or combined with each other. | ||
|
||
However, in this case, there are some unique benefits and reasons for why this sample extension does not follow those patterns such as easier management of conflicting dependencies and configurations, as well as the ability to use the Vite dev server, which drastically improves the speed of developing your webview UI, versus recompiling your extension code every time you make a change to the webview. |
Oops, something went wrong.