UNPKG

2.88 kBTypeScriptView Raw
1import { Plugin } from 'vite';
2import { Options } from 'tsup';
3
4/**
5 * vscode extension options. See [tsup](https://tsup.egoist.dev/) and [API Doc](https://paka.dev/npm/tsup) for more information.
6 */
7interface ExtensionOptions extends Omit<Options, 'entry' | 'format' | 'outDir' | 'watch' | 'onSuccess' | 'skipNodeModulesBundle'> {
8 /**
9 * The extension entry file.
10 * @default "extension/index.ts"
11 */
12 entry?: string;
13 /**
14 * The output directory for the extension files. Default is `dist-extension`.
15 * @default "dist-extension"
16 */
17 outDir?: string;
18 /**
19 * The bundle format. Currently only supports cjs.
20 */
21 format?: 'cjs';
22 /**
23 * Skip dependencies and peerDependencies bundle. Default is false.
24 */
25 skipNodeModulesBundle?: boolean;
26 /**
27 * A function that will be executed after the build succeeds.
28 */
29 onSuccess?: () => Promise<void | undefined | (() => void | Promise<void>)>;
30}
31/**
32 * vite plugin options.
33 */
34interface PluginOptions {
35 /**
36 * Recommended switch. Default is true.
37 * if true, will have the following default behavior:
38 * * will change the extension/webview outDir to be parallel outDir;
39 * eg. if vite build.outDir is 'dist', will change extension/webview to 'dist/extension' and 'dist/webview'
40 * @default true
41 */
42 recommended?: boolean;
43 /**
44 * Inject [@tomjs/vscode-extension-webview](https://github.com/tomjs/vscode-extension-webview) into vscode extension code and web client code, so that webview can support HMR during the development stage.
45 *
46 * * vite serve
47 * * extension: Inject `import __getWebviewHtml__ from '@tomjs/vscode-extension-webview';` above the file that calls the `__getWebviewHtml__` method
48 * * web: Add `<script>` tag to index.html and inject `@tomjs/vscode-extension-webview/client` code
49 * * vite build
50 * * extension: Inject `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode-inject';` above the file that calls the `__getWebviewHtml__` method
51 *
52 * If is string, will set inject method name. Default is '__getWebviewHtml__'.
53 *
54 * @example
55 * extension file
56 * ```ts
57 *function setupHtml(webview: Webview, context: ExtensionContext) {
58 * if (process.env.VITE_DEV_SERVER_URL) {
59 * return __getWebviewHtml__(process.env.VITE_DEV_SERVER_URL);
60 * }
61 * return __getWebviewHtml__(webview, context);
62 *}
63 * ```
64 * webview client
65 * ```html
66 * <html>
67 * <head>
68 * <script>inject code</script>
69 * </head>
70 * </html>
71 * ```
72 */
73 webview?: boolean | string;
74 /**
75 * extension vite config.
76 */
77 extension?: ExtensionOptions;
78}
79
80declare function useVSCodePlugin(options?: PluginOptions): Plugin[];
81
82export { useVSCodePlugin as default, useVSCodePlugin };
83
\No newline at end of file