{"id":22791,"library":"vite-plugin-public-typescript","title":"vite-plugin-public-typescript","description":"Vite plugin that injects TypeScript code directly into HTML as inline scripts, transforming TypeScript to JavaScript during build. Current stable version is 4.2.1, with frequent releases following Vite major versions. Key differentiators: allows using TypeScript in public scripts without separate bundling, supports both development and production modes, and provides type-safe script injection. Requires Vite >=5 as peer dependency. Released under MIT license.","status":"active","version":"4.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/hemengke1997/vite-plugin-public-typescript","tags":["javascript","vite","typescript","public-typescript","inject script","html"],"install":[{"cmd":"npm install vite-plugin-public-typescript","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-public-typescript","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-public-typescript","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: Vite >=5 required for plugin to function","package":"vite","optional":false}],"imports":[{"note":"ESM-only package; default export is the plugin function","wrong":"const vitePluginPublicTypescript = require('vite-plugin-public-typescript')","symbol":"vitePluginPublicTypescript","correct":"import vitePluginPublicTypescript from 'vite-plugin-public-typescript'"},{"note":"Type only import to avoid bundling; plugin function accepts this type","wrong":"import { PluginOptions } from 'vite-plugin-public-typescript'","symbol":"PluginOptions","correct":"import type { PluginOptions } from 'vite-plugin-public-typescript'"},{"note":"Default export, not named export","wrong":"import { vitePluginPublicTypescript } from 'vite-plugin-public-typescript'","symbol":"vitePluginPublicTypescript","correct":"import vitePluginPublicTypescript from 'vite-plugin-public-typescript'"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite'\nimport vitePluginPublicTypescript from 'vite-plugin-public-typescript'\n\nexport default defineConfig({\n  plugins: [\n    vitePluginPublicTypescript({\n      // Paths to TypeScript files to inject into HTML\n      files: ['src/scripts/analytics.ts', 'src/scripts/init.ts'],\n      // Optional: inject into specific HTML files\n      htmlFiles: ['index.html'],\n      // Optional: remove script tags after build\n      removeScriptTags: false\n    })\n  ]\n})","lang":"typescript","description":"Shows how to configure the plugin in vite.config.ts, injecting two TypeScript files into the HTML."},"warnings":[{"fix":"Upgrade Vite to >=5, or use v3.x of the plugin with Vite 4","message":"Version 4.x requires Vite >=5; incompatible with Vite 4.x","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Only use browser-compatible code in your TypeScript files","message":"TypeScript files are evaluated in the browser; avoid importing Node.js modules","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set `base` in Vite's defineConfig, not in plugin options","message":"The `base` option is deprecated in v4; use Vite's `base` config instead","severity":"deprecated","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Ensure the plugin is called inside `plugins` array of Vite's defineConfig. If using a custom config file, specify via `--config`","cause":"Plugin tried to detect Vite config but failed","error":"Error: No matching vite config found"},{"fix":"Change to ESM: use `import` syntax, or set `\"type\": \"module\"` in package.json","cause":"Using CommonJS `require` to import the ESM-only plugin","error":"SyntaxError: Unexpected token 'export'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}