{"id":13810526,"url":"https://github.com/patak-dev/vite-plugin-terminal","last_synced_at":"2025-04-13T00:40:43.015Z","repository":{"id":39865048,"uuid":"450058075","full_name":"patak-dev/vite-plugin-terminal","owner":"patak-dev","description":"Log in the node terminal from the browser","archived":false,"fork":false,"pushed_at":"2024-05-11T08:14:12.000Z","size":1069,"stargazers_count":267,"open_issues_count":5,"forks_count":17,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-10-30T02:36:07.942Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patak-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["patak-dev"]}},"created_at":"2022-01-20T10:50:48.000Z","updated_at":"2024-10-16T21:41:36.000Z","dependencies_parsed_at":"2024-01-10T18:10:29.041Z","dependency_job_id":"ea4bfc14-a7dd-404d-ac00-4b87479552e2","html_url":"https://github.com/patak-dev/vite-plugin-terminal","commit_stats":{"total_commits":58,"total_committers":12,"mean_commits":4.833333333333333,"dds":0.3448275862068966,"last_synced_commit":"d2017d02803ced7ec4f196fb5fc2bffca1c9e78a"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patak-dev%2Fvite-plugin-terminal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patak-dev%2Fvite-plugin-terminal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patak-dev%2Fvite-plugin-terminal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patak-dev%2Fvite-plugin-terminal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patak-dev","download_url":"https://codeload.github.com/patak-dev/vite-plugin-terminal/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650414,"owners_count":21139672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-04T02:00:57.873Z","updated_at":"2025-04-13T00:40:42.985Z","avatar_url":"https://github.com/patak-dev.png","language":"TypeScript","funding_links":["https://github.com/sponsors/patak-dev"],"categories":["TypeScript","others"],"sub_categories":[],"readme":"# vite-plugin-terminal\n\n[![NPM version](https://img.shields.io/npm/v/vite-plugin-terminal?color=a1b858\u0026label=)](https://www.npmjs.com/package/vite-plugin-terminal)\n\nLog in the node terminal from the browser\n\n![](https://github.com/patak-dev/vite-plugin-terminal/blob/76fb5c2656e99a8619986be2bff5c26414273a66/vite-plugin-terminal.png)\n\n[Open a playground online in StackBlitz](https://stackblitz.com/fork/github-bdbxen-madd1h?file=module.js\u0026terminal=dev)\n\n## Install\n\n```bash\nnpm i -D vite-plugin-terminal\n```\n\nAdd plugin to your `vite.config.ts`:\n\n```ts\n// vite.config.ts\nimport Terminal from 'vite-plugin-terminal'\n\nexport default {\n  plugins: [\n    Terminal()\n  ]\n}\n```\n\n## Usage\n\nIn your source code import `terminal`, and use it like you do with `console.log`.\n\n```ts\nimport { terminal } from 'virtual:terminal'\n\nterminal.log('Hey terminal! A message from the browser')\n```\n\nThe terminal log calls will be removed when building the app.\n\n## Types\n\nThere are two ways of telling typescript about the types of the virtual import:\n\n- In your `global.d.ts` file add the following line:\n  ```ts\n  /// \u003creference types=\"vite-plugin-terminal/client\" /\u003e\n  ```\n\n- In your `tsconfig.json` add the following to your `compilerOptions.types` array:\n\n  ```json\n  {\n    // ...\n    \"compilerOptions\": {\n      // ...\n      \"types\": [\n        \"vite-plugin-terminal/client\"\n      ],\n    },\n  }\n  ```\n\n\n## API\n\nSupported methods:\n- `terminal.log(obj1 [, obj2, ..., objN])`\n- `terminal.info(obj1 [, obj2, ..., objN])`\n- `terminal.warn(obj1 [, obj2, ..., objN])`\n- `terminal.error(obj1 [, obj2, ..., objN])`\n- `terminal.assert(assertion, obj1 [, obj2, ..., objN])`\n- `terminal.group()`\n- `terminal.groupCollapsed()`\n- `terminal.groupEnd()`\n- `terminal.table(obj)`\n- `terminal.time(id)`\n- `terminal.timeLog(id, obj1 [, obj2, ..., objN])`\n- `terminal.timeEnd(id)`\n- `terminal.clear()`\n- `terminal.count(label)`\n- `terminal.countReset(label)`\n- `terminal.dir(obj)` \n- `terminal.dirxml(obj)` \n\nThese methods will work but use the console\n\n- `terminal.trace(...args: any[])`\n- `terminal.profile(...args: any[])`\n- `terminal.profileEnd(...args: any[])`\n\n## Redirect `console` logs to the terminal\n\nIf you want the standard `console` logs to appear in the terminal, you can use the `console: 'terminal'` option in your `vite.config.ts`:\n\n```ts\n// vite.config.ts\nimport Terminal from 'vite-plugin-terminal'\n\nexport default {\n  plugins: [\n    Terminal({\n      console: 'terminal'\n    })\n  ]\n}\n```\n\nIn this case, you don't need to import the virtual terminal to use the plugin.\n\n```ts\nconsole.log('Hey terminal! A message from the browser')\n```\n\nYou can also overwrite it in your `index.html` head manually in case you would like more control.\n\n```html\n  \u003cscript type=\"module\"\u003e\n    // Redirect console logs to the terminal\n    import terminal from 'virtual:terminal'\n    globalThis.console = terminal\n  \u003c/script\u003e\n```\n\nCheck the [Console playground](./playground/console) for a full example.\n\n## Log in both the terminal and the console\n\nYou can use the `output` option to define where the `terminal` logs should be logged. Accepts `terminal`, `console`, or an array with both.\n\n```ts\n// vite.config.ts\nimport Terminal from 'vite-plugin-terminal'\n\nexport default {\n  plugins: [\n    Terminal({\n      output: ['terminal', 'console']\n    })\n  ]\n}\n```\n\n## Examples\n\n- **[Basic](https://stackblitz.com/fork/github-bdbxen-madd1h?file=module.js\u0026terminal=dev)** - Playground using every available method.\n- **[Console](https://stackblitz.com/fork/github/patak-dev/vite-plugin-terminal/tree/main/playground/console)** - Redirect standard console logs to the terminal.\n- **[Auto Import](https://stackblitz.com/fork/github-ejosid?file=main.ts\u0026terminal=dev)** - Use [unplugin-auto-import](https://github.com/antfu/unplugin-auto-import) to make `terminal` global in your app.\n- **[Vue](https://stackblitz.com/fork/github-gzl5vm?file=src%2FApp.vue\u0026terminal=dev)** - Example of logging to the terminal from a Vue App.\n\n## Options\n\n### `console`\n\nType: `'terminal' | undefined`\u003cbr\u003e\nDefault: `undefined`\u003cbr\u003e\n\nSet to `'terminal'` to make `globalThis.console` equal to the `terminal` object in your app.\n\n### `output`\n\nType: `'terminal' | 'console' | ['terminal', 'console']`\u003cbr\u003e\nDefault: `terminal`\u003cbr\u003e\n\nDefine where the output for the logs.\n\n### `strip`\n\nType: `boolean`\u003cbr\u003e\nDefault: `true`\u003cbr\u003e\n\nStrip `terminal.*()` when bundling for production.\n\n### `include`\n\nType: `String | RegExp | Array[...String|RegExp]`\u003cbr\u003e\nDefault: `/.+\\.(js|ts|mjs|cjs|mts|cts)/`\u003cbr\u003e\nExample: `include: '**/*.(mjs|js)',`\u003cbr\u003e\n\nA pattern, or array of patterns, which specify the files in the build the plugin should operate on when removing calls for production.\n\n### `exclude`\n\nType: `String | RegExp | Array[...String|RegExp]`\u003cbr\u003e\nDefault: `[]`\u003cbr\u003e\nExample: `exlude: 'tests/**/*',`\u003cbr\u003e\n\nA pattern, or array of patterns, which specify the files in the build the plugin should _ignore_ when removing calls for production.\n\n## Credits\n\n- Original idea from [Domenic Elm](https://twitter.com/elmd_)\n- Project setup from [@antfu's vite-plugin-inspect](https://github.com/antfu/vite-plugin-inspect)\n- Bundling by [unbuild](https://github.com/unjs/unbuild)\n- Strip functions during build uses [rollup-plugin-strip](https://github.com/rollup/plugins/tree/master/packages/strip)\n\n## Sponsors\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://patak.dev/sponsors.svg\"\u003e\n    \u003cimg src=\"https://patak.dev/sponsors.svg\"/\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## License\n\n[MIT](./LICENSE) License © 2022-present [Matias Capeletto](https://github.com/patak-dev)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatak-dev%2Fvite-plugin-terminal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatak-dev%2Fvite-plugin-terminal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatak-dev%2Fvite-plugin-terminal/lists"}